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
5 Answers
Reset to default 6Second 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.