我想用用户通过 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")
关于javascript - 无法通过 Prompt() 打开带有网站 URL 的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57613928/