How can I read get parameters passed to a JS file like so:
<script type="text/javascript" src="/script.js?p1=开发者_Go百科hello&p2=world"></script>
In the same file (script.js) I want to read the p1 and p2 values like:
var p1 = params["p1"];
I'd rather avoid a method that getElementById's or uses the dom anyway. thanks.
No magic that I'm aware of here... As the script is loaded, the tag is added to the dom tree and you can read from it using document.getElementsByTagName('script') and then parse the results.
Full code given here : http://feather.elektrum.org/book/src.html
See this answer. You then have to parse the result yourself.
How to check for script src match, then reassign src
精彩评论