Javascript:在一个循环给出正确答案后打开URL

Javascript: open URL after a loop gives a right answer

本文关键字:答案 URL 循环 一个 Javascript      更新时间:2023-09-26

我想不通:

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 {
            ;
        }

循环应该保持一个人直到他输入正确的单词(在我的例子中是谷歌或必应(。然而,下一个打开这个url的函数无法工作。(我不想使用select/选项(。另外,结尾"else"在我看来也很可疑。

谢谢。

window.location不是函数。你的意思是使用window.open

您应该使用以下内容:

window.open( url );

location.href = url;