无法打开包含来自 prompt() 的网站 URL 的窗口



我想用用户使用 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")
}

没有错误,但没有包含预期结果的窗口。预期结果是一个窗口,其中包含用户输入的网站。

您将变量错误地传递给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")

最新更新