2012-05-03 81 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

相关问题