最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.open not opening window - Stack Overflow

programmeradmin4浏览0评论

I'm trying to open a page in a popup as opposed to new tab - but whichever browser I try this simply opens in a new tab, not popup.

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

Any reason why?

I'm trying to open a page in a popup as opposed to new tab - but whichever browser I try this simply opens in a new tab, not popup.

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

Any reason why?

Share Improve this question asked Oct 16, 2012 at 10:30 StudioTimeStudioTime 24k40 gold badges128 silver badges215 bronze badges 1
  • I think that what you're facing is due to the fact that modern browsers are configured to open popups in new tabs... – Matteo Tassinari Commented Oct 16, 2012 at 10:32
Add a ment  | 

5 Answers 5

Reset to default 6

Second parameter must be the window name:

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

Working fine in Chrome and Firefox:

http://jsfiddle/DvMy5/2/

The second parameter should be name..Something like windowname

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

JSFiddle

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

window.open method is as follow.

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

Here is a good read Window open() Method

name Optional. Specifies the target attribute or the name of the window. The following values are supported:

_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

The problem is the 3rd argument to window.open. When you pass the 3rd argument, the browser will open a new window provided the window name(second argument is not already opened). window.open("http://localhost:5000", "newWindow", "resizable")will open window but window.open("http://localhost:5000", "newWindow") will open a tab.

Isn't this something controlled by the various browsers? Using target="_blank" opens in a new tab in Chrome, and my guess is that this also apply for Firefox, Opera, Safari and IE.

发布评论

评论列表(0)

  1. 暂无评论