无法打开带有提示()中的网站URL的窗口

时间:2019-08-22 16:52:33

标签: javascript

我想用用户通过open方法输入的网站创建一个新窗口,但是我似乎找不到问题的答案。

// beginning of input
var input = document.createElement("input")
input.setAttribute("value","Create Window")
input.setAttribute("type","button")
input.id = "input";
document.body.appendChild(input)
// end of input
// beginning of input2
var input2 = document.createElement("input")
input2.setAttribute("value", "close window")
input2.setAttribute("type","button")
input2.id = "input2";
document.body.appendChild(input2)
// end of input2
function createWindow(){
    var prompt0 = prompt("what is the name of the website that you want to go to:")
    open("prompt0","newWindow","height=500,width=400,toolbar=1,titlebar=1,menubar=yes")
}

没有错误,但是没有期望结果的窗口。预期结果是用户输入网站的窗口。

1 个答案:

答案 0 :(得分:4)

您错误地将变量传递给open,该变量不应包含引号,因为这会使它成为字符串。

var prompt0 = prompt("what is the name of the website that you want to go to:")
open(prompt0,"newWindow","height=500,width=400,toolbar=1,titlebar=1,menubar=yes")