我想在用户点击按钮时从外部网站加载JS代码。例如:
<button onclick="LoadJSFromURL('facebook.com/blablabla')" />
当用户按下按钮时,我们将新脚本附加到文档:
<script> Share.WorkUrl="http://MySite.com"; Share.UserId=5 </script> <script src="http://Facebookcom/blabalbal" ></script>
然后我们必须执行这个脚本。这是真的吗?
答案 0 :(得分:2)
检查一下:How do you dynamically load a javascript file from different domain?
var script = new Element("script", {src: "myBigCodeLibrary.js", type: "text/javascript"});
script.onload = script.onreadystatechange = function(){
if (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") {
//script is loaded
}
};