2011-11-04 65 views
0

我有一個頁面只包含一個字符串,需要從不同域中的頁面讀取它。我試圖通過動態腳本hack(爲了避免安全限制)來做到這一點,並且可以讀取該字符串,但無法將其帶入回調中,以便在變量中繼續使用它。動態腳本hack回調

我的問題是,我需要做它只使用JavaScript。

這裏是我目前使用的代碼:

的index.html:

<html> 
<head> 
<script type="text/javascript"> 
    function xss_ajax(url) { 
     var script_id = null; 
     var script = document.createElement('script'); 
     script.setAttribute('type', 'text/javascript'); 
     script.setAttribute('src', url); 
     script.setAttribute('id', 'script_id'); 

     script_id = document.getElementById('script_id'); 
     if(script_id){ 
      document.getElementsByTagName('head')[0].removeChild(script_id); 
     } 

     document.getElementsByTagName('head')[0].appendChild(script); 
    } 

    var url = "http://otherdomain.com/ping.html"; 

    xss_ajax(url); 
</script> 
</head> 
<body> 
</body> 
</html> 

ping.html:

1|1739 

非常多的感謝和抱歉,我英語。

回答

0

你的結果從ping.html劑量不會有任何變量定義的,如果你說

取得的對象像

result = [1,1739]; 

,並在你的index.html聲明

var result = []; 

,那麼你可以與此一起工作。