2012-05-03 77 views
0

我有一個奇怪的問題。在一些瀏覽器(如chrome)下面的代碼打開一個新窗口。所以它按預期工作。在其他瀏覽器(如Firefox)它只顯示警告框所以它不會打開請求的窗口。 任何適用於所有瀏覽器的代碼的建議?javascript:window.location在所有瀏覽器上都無法打開新窗口

if(TestVar == "1810") 
      { 
       alert ("test " + TestVar + "! "); 
       window.location.href="http://astyle.home.xs4all.nl/beautyfarm2003/wellnessbon_321442.html"; 
      } 

if(TestVar == "1920") 
      { 
       alert ("Test " + TestVar + "! "); 
       window.location="http://astyle.home.xs4all.nl/beautyfarm2003/wellnessbon_1925485.html"; 
      } // Vriendinnendag 
+0

打開一個新窗口,又名,你的意思是它並不導航到新的頁面?你聽起來像你使用window.open(),但你不是。 – epascarello

回答

0

該代碼似乎在我的Chrome,Internet Explorer 9/10和Firefox中工作得很好。

嘗試以下操作:http://jsbin.com/uluziz/edit#javascript,html

如果你想打開一個新窗口,你將不會被改變window.location。那只是改變位置你的當前窗口在。使用window.open()而不是打開一個新窗口到新的位置:

var myWin = window.open('http://stackoverflow.com','SO','width=640,height=480'); 

setTimeout(function(){ 
    myWin.close(); 
}, 2000); 

演示:http://jsbin.com/ekoluk/3/edit

相關問題