如何在客户端更改Javascript src文件? [英] How do I change the Javascript src file on client side?
问题描述
< script src =http://maps.google。 com / maps?file = api& amp; v = 2.x& amp; amp; key = ABQIAAkh87y8Hjhg76tytype =text / javascript>< / script>
可以在页面的头部添加Javascript或jQuery来更改key参数在脚本源中。我想在渲染到达上面的标签之前这样做。
不可能更改<$ c $因为现代浏览器会一到达脚本标签(以特定的格式)即可下载并解析脚本,因此渲染到达标签之前,c> src 属性 / p>
您可以使用 defer
属性来阻止脚本的执行,直到DOM完全加载,但这属性仅在IE 4+和Firefox 3.5 +中支持。
Within my body tag, I have this:
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAkh87y8Hjhg76ty" type="text/javascript"></script>
Is it possible to add Javascript or jQuery in the head of the page to change the "key" parameter in the script source. I am trying to do this before the render reaches the above tag.
It is not possible to change the src
attribute before the render reaches the tag, because modern browsers will download and parse the script as soon as it reaches a script tag (in that particular format).
You can use the defer
attribute to hold off execution of the script until after the DOM has completely loaded, but this attribute is only supported in IE 4+ and Firefox 3.5+.
这篇关于如何在客户端更改Javascript src文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!