如何在客户端更改Javascript src文件? [英] How do I change the Javascript src file on client side?

查看:106
本文介绍了如何在客户端更改Javascript src文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < 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&amp;v=2.x&amp;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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆