2013-02-27 62 views
0

我不知道这一点:的Javascript:一个循环后打开URL给出了正确的答案

var right = {"Google" :1, "Bing" :1} 

     do { 
      var website = prompt("Where should I redirect you: Google, Yahoo!, ebay or CCSF?", "");   
     } while (!right[website]); 

     if (website == "Google") { 
      var url = "https://www.google.com/"; 
      window.location(url, '_blank'); 
      window.focus(); 
     } else if (website == "Bing") { 
      var url = "http://www.bing.com/"; 
      window.location(url, '_blank'); 
      window.focus(); 
     } else { 
      ; 
     } 

应该保持一个人,直到他在正确的字类型(谷歌或冰在我的例子中环)。但是,下一个功能打开此网址无法正常工作。 (我不想使用选择/选项)。另外,结束“其他”也看起来对我很可疑。

谢谢。

回答

2

window.location不是功能。你的意思是使用window.open

+0

太好了!就是这么简单:)谢谢。它打开我一个新的窗口,而不是新的标签虽然... – Art 2013-02-27 00:53:17

+0

尝试没有'_blank',但这也取决于浏览器设置 – 2013-02-27 00:55:58

0

您应该用户是这样的:

window.open(url); 

location.href = url; 
相关问题