开发者

Read javascript .js get parameters

开发者 https://www.devze.com 2023-03-27 00:32 出处:网络
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>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消