2013-06-28 77 views
-1

當我點擊鏈接時,它會在Firefox,Opera Mini中打開兩個彈出窗口...還有其他方法可以做到這一點嗎?在Firefox中打開兩個彈出窗口,鍍鉻

<script type="text/javascript"> 

window.onload=function() { 
    var links = document.getElementsByTagName("a"); 
    for(var i=0; i<links.length; i++) {  
    var string = links[i].href; //href value 
    var str = string;  
    var spl = string.split("/"); 
    switch(spl[2]) 
    { 
     case 'www.google.com': 
      var str1 = "http://yahoo.com"; 
      links[i].target="_blank"; 
      links[i].href = links[i].addEventListener("click", function(){var windowObjectReference = window.open(str1)}, false); 
      break; 

     default: 
      links[i].target="_blank"; 
      links[i].href= string; 
    } 

} 
} 

</script> 

<a href="http://www.google.com/" target="-blank">www.google.com</a></br> 
+0

是否在您調用彈出窗口時重新加載頁面? –

+0

不是它打開兩個窗口與實際的鏈接和一個錯誤頁面請檢查在Firefox – user2520639

回答

0

您的代碼中有雙重動作。看到我的版本的差異。

<script type="text/javascript"> 

window.onload=function() { 
    var links = document.getElementsByTagName("a"); 
    for(var i=0; i<links.length; i++) {  
    var string = links[i].href; //href value 
    var str = string;  
    var spl = string.split("/"); 
    switch(spl[2]) 
    { 
     case 'www.google.com': 
      var str1 = "http://yahoo.com"; 
      links[i].target="_blank"; 
      links[i].href = str1; 
      break; 

     default: 
      links[i].target="_blank"; 
      links[i].href= string; 
    } 

} 
} 

</script> 

<a href="http://www.google.com/" target="-blank">www.google.com</a></br>