window.open没有打开窗口

时间:2012-10-16 10:30:38

标签: javascript html window.open

我试图在弹出窗口中打开一个页面而不是新标签 - 但无论我尝试使用哪个浏览器,只需在新标签页中打开,而不是弹出窗口。

<input type="button" value="new win" onclick="window.open('http://yahoo.com', 'width=500, height=400')"  />

有什么理由?

5 个答案:

答案 0 :(得分:4)

第二个参数必须是窗口名称:

<input type="button" value="new win" 
    onclick="window.open('http://yahoo.com', 'mywindow', 'width=500, height=400')"  />

在Chrome和Firefox中正常运行:

http://jsfiddle.net/DvMy5/2/

答案 1 :(得分:2)

第二个参数应该是name..Something like windowname

<input type="button" value="new win" 
onclick="window.open('http://yahoo.com','windowname', 'width=500, height=400')"  />

答案 2 :(得分:2)

JSFiddle

onclick="window.open('http://yahoo.com', 'MyYahoo', 'width=500, height=400, toolbar=no, menubar=no')"  />

window.open方法如下。

window.open(URL,name,specs,replace)

这是一篇很好的阅读Window open() Method

  

name可选。指定目标属性或名称   窗口。支持以下值:

_blank - URL is loaded into a new window. This is default
_parent - URL is loaded into the parent frame
_self - URL replaces the current page
_top - URL replaces any framesets that may be loaded
name - The name of the window

答案 3 :(得分:0)

这不是由各种浏览器控制的吗?使用target =“_ blank”会在Chrome的新标签页中打开,我的猜测是这也适用于Firefox,Opera,Safari和IE。

答案 4 :(得分:0)

问题是window.open的第三个参数。当您传递第三个参数时,如果窗口名称(第二个参数尚未打开),浏览器将打开一个新窗口。 .[] | select(.Conditions[].Values[]? == "app.fantastic.com") | .RuleArn 将打开窗口,但window.open("http://localhost:5000", "newWindow", "resizable")将打开一个标签。

相关问题