I have the following script declared in the document of my head:
<script src="http://www.domain.com/js/widgets.js" type="text/javascript"></script>
Which points to this:
widgets.js
(function () {
var styleEl = document.createElement("link");
styleEl.type = "text/css";
styleEl.href = "http://127.0.0.1:8002/static/css/widgets.css";
styleEl.rel = "stylesheet";
//document.getElementsByTagName('head')[0].appendChild(styleEl);
document.head.appendChild(styleEl);
document.write("<div id='share_box'>" +
"<a href='test' target='_blank'>R</a>" +
"</div>");
})();
I would like to pass in variable to this external file, this is what I have tried:
<script src="widgets.js" type="text/javascript">
var url = 'https://www.domain.com/link/'
</script>
How can I pass in the variable URL to my external script? (in a safe way using javascript only - no jquery)
<script>tag above, and then access it. Although if you are going to have more than one you should consider using an object to avoid polluting the global namespace.widget.jsscript that a change has been made tourlsomehow. Simply changing the string value of that variable won't automatically update any objects that use it.