我有一个动态加载的脚本(确切地说是谷歌地图),由于几个原因,我无法改变默认情况下最初加载的方式。
通过JavaScript,我想找到字符串libraries=places
并在事后
libraries=places,visualization
所以,最初的输出:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?libraries=places">
</script>
将是:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?libraries=places,visualization">
</script>
这甚至可能吗?
提前致谢
答案 0 :(得分:0)
此解决方案也适用于您的解决方案: How do I include a JavaScript file in another JavaScript file?
windows -> preference -> server -> Runtime Environments. To the right of Runtime Environments, you should see the servers. Remove Tomcat 8.0 and add Tomcat v9.0. Rebuild project.
将是您添加src网址的行,但是您喜欢
答案 1 :(得分:-1)
首先给谷歌地图脚本标签一个ID:
<script id="google_map_script" type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
然后做:
var google_map_script = document.getElementById("google_map_script")
google_map_script.setAttribute("src", "https://maps.googleapis.com/maps/api/js?libraries=places,visualization")
编辑:因为显然这不是什么需要然后呢:
var script = document.createElement('script');
my_awesome_script.setAttribute('src','https://maps.googleapis.com/maps/api/js?libraries=places,visualization');
document.head.appendChild(script);
另请参阅使用postscribe。