admin管理员组文章数量:1366372
Is something like this possible?
<script src=".js" my-custom-header="foo"></script>
Update (a bit more detail):
I've been asked if there was a way to municate some parameters to the server as part of the script request using headers instead of GET params. I said, "no," but thought I'd double check.
Is something like this possible?
<script src="http://myserver./some.js" my-custom-header="foo"></script>
Update (a bit more detail):
I've been asked if there was a way to municate some parameters to the server as part of the script request using headers instead of GET params. I said, "no," but thought I'd double check.
Share Improve this question edited Feb 1, 2011 at 19:00 sprugman asked Feb 1, 2011 at 18:54 sprugmansprugman 19.8k36 gold badges115 silver badges164 bronze badges 3- Which header(s) did you want to have set? – Cameron Commented Feb 1, 2011 at 18:59
- Why can't you use GET params? – Cameron Commented Feb 1, 2011 at 19:02
- The worry is about running out of room in the url space. And also having to parse them out, I guess. (I gather we have a custom parser, so it's not as simple as $_GET['myParam'].) – sprugman Commented Feb 1, 2011 at 19:04
2 Answers
Reset to default 6Short answer: no. By default a script tag will just retrieve the resource specified in the src
attribute.
However, if you use an AJAX request to retrieve the script (and add it later/execute it), you can use the setRequestHeader
function of the XMLHttpRequest
object (see http://www.developertutorials./learn-ajax/custom-http-headers-2643.php).
You could also use more plex methods, such as using mod_rewrite
to rewrite paths, and include the parameters in the url. The best solution depends on what you want to do, and how much control you have over the server.
No. You'll need to set the headers on the server that's serving up the JS file.
EDIT: I misinterpreted what you meant, it turns out you wanted to set a request header, not a response header. This is still not possible (from HTML) as far as I know.
本文标签: javascriptis it possible to set custom headers on js ltscriptgt requestsStack Overflow
版权声明:本文标题:javascript - is it possible to set custom headers on js <script> requests? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743696618a2523610.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论