3

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.com', 'width=500, height=400')" />

Any reason why?

asked Oct 16, 2012 at 10:30
1
  • I think that what you're facing is due to the fact that modern browsers are configured to open popups in new tabs... Commented Oct 16, 2012 at 10:32

5 Answers 5

6

Second parameter must be the window name:

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

Working fine in Chrome and Firefox:

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

answered Oct 16, 2012 at 10:33
Sign up to request clarification or add additional context in comments.

1 Comment

Aaaaargh!! Schoolboy error! Thanks so much - will accept as soon as it lets me
2

The second parameter should be name..Something like windowname

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

Comments

2

JSFiddle

onclick="window.open('http://yahoo.com', '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
answered Oct 16, 2012 at 10:35

Comments

2

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.

answered Apr 30, 2020 at 23:21

1 Comment

That's true. The syntax is: window.open(URL, name, specs, replace). To answer the question, the second argument (name) was missing, so adding a blank name solves that: window.open('yahoo.com', '','width=500, height=400');
0

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.

answered Oct 16, 2012 at 10:34

1 Comment

That guess is indeed right. But I think that only applies to <a /> elements.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.