2011-03-24 36 views
2

我想在用戶點擊按鈕時從外部網站加載JS代碼。例如:從外部網站上運行加載js

<button onclick="LoadJSFromURL('facebook.com/blablabla')" /> 

,當用戶按下按鈕,我們重視新的腳本文件:

<script> Share.WorkUrl="http://MySite.com"; Share.UserId=5 </script> <script src="http://Facebookcom/blabalbal" ></script> 

,然後我們必須執行這個腳本。這是真的嗎?

回答

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 
    } 
}; 
+0

這是否解決方案依賴於原型? – o01 2012-03-03 21:58:54