tags:

views:

12474

answers:

10

I have a select box that calls window.open(url) when an item is selected. Firefox will open the page in a new tab by default. However, I would like the page to open in a new window, not a new tab.

How can I accomplish this?

+6  A: 

You shouldn't need to. Allow the user to have whatever preferences they want.

Firefox does that by default because opening a page in a new window is annoying and a page should never be allowed to do so if that is not what is desired by the user. (Firefox does allow you to open tabs in a new window if you set it that way).

CookieOfFortune
you are so wrong. and by the way, saying "you shouldnt need to" is not appropriate, especially if it is something the boss wants
Right, I could shift+click a hyperlink, but in this case window.open(url) is executed on the event of selecting a dropdown option. So that method doesn't work. Opening in a new window is an intentional part of the design specs.
adam
the boss sounds like he has pointy hair
Blank Xavier
Lets try and keep the comments practical and helpful. We can disagree without being insulting.
adam
@theman_on_vista: Convincing your boss is *your* responsibility. Your company has bestowed on you the responsibility to resolve design issues. This includes pointing out wrong design ideas.
EFraim
So true. The screen belongs to the user, and no one else.
Christopher Creutzig
+15  A: 

I may be wrong, but from what I understand, this is controlled by the user's browser preferences, and I do not believe that this can be overridden.

Jordan S. Jones
You are right, the user can set the "about:config" preference "browser.tabs.opentabfor.windowopen" to true, but that is a global setting and I do not want to change the global behavior of our users browsers ;)
adam
I told you I have code that works. I typed this into firebug console:window.open("", "poop", "height=200,width=200,modal=yes,alwaysRaised=yes");and guess what??? it works!!!!!!
DNS answer is correct too
Yes it works, but this seems to be a bit of a hack. Firefox is written in such a way that opening a new window vs tab is a browser preference, not a javascript preference. Therefore it is feasible that your suggestion wont work the same in a later version of firefox. I'd rather not rely on a hack.
adam
And to be clear, I don't mean it's a javascript hack. Adding window height and width are clearly features of the js window.open method (http://www.w3schools.com/HTMLDOM/met_win_open.asp) I mean hack in the sense of manipulating the intended behavior of firefox.
adam
I wouldn't really call it a hack, per se. You're just compromising on what behavior you'd actually like to have, and implementing that, instead.
Matchu
Instead of saying "sorry to be rude" why not be nice? It think that is a much better idea.
Rimian
+7  A: 

Try:

    window.open("", [window name], "height=XXX,width=XXX,modal=yes,alwaysRaised=yes");

I have some code that does what your say, but there is a lot of parameters in it. I think these are the bare minimum, let me know if it doesn't work, I'll post the rest.

+17  A: 

Give the window a 'specs' parameter with width/height. See here for all the possible options.

window.open(url, windowName, "height=200, width=200");

When you specify a width/height, it opens it in a new window instead of a tab.

DNS
Good tip. I think Opera will still open this in a tab though :).
Kevin Tighe
Doesn't think it works in FF or Chrome (beta versions of both though, dunno about behavior for non-beta).
CookieOfFortune
It should work in Firefox (I checked before posting); haven't tried Chrome. And yeah, it's by no means a solid cross-browser solution; the whole situation is kind of a mess.
DNS
question references firefox, not any other browser
Your advice is right on, but your syntax is incorrect.
D_N
This is correct, although there are certain non-default browser settings (Safari 5 has one, for example) that blocks even this (it instead opens in a new tab and ignores the specified size).
philfreo
A: 

No 5 answer worked for me in Firefox 3.5.5 12/9/2009 . Specify a window size and get a pop up new window, leave it blank and get a new tab.

Stuart
I wanted to open in tab instead of window and it works for me. Do not specify size and you get in new tab
vsingh
+3  A: 

You don't need to use height, just make sure you use _blank, Without it, it opens in a new tab.

For a empty window:

window.open('', '_blank', 'toolbar=0,location=0,menubar=0');

For a specific URL:

window.open('http://www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');
nwbrad
A: 

I wanted to open the window in new tab or new window in FF and bring the focus back on main window. Somehow window.focus() or window,blur does not seem to work

vsingh
+1  A: 

I know this is a relatively old question, but I want to point out that the accepted answer doesn't work on my browser (I'm not complaining, by the way, I myself wouldn't want that to work in my browser). I'm using Firefox 3.6, and have modified a number of about:config entries regarding opening in new windows (I don't want a website opening up a non-resizable window, for example). I don't know which part of this configuration makes the hack not work, so future readers will have to play around with it.

user4815162342
A: 

I find it so obnoxious and ignorant when people respond to a thread asking how to do something with, "don't," talking about how they wouldn't want that to work. Nobody asked for your lame, narrow minded opinion on whether the functionality is good or not.

There are many valid reasons for wanting this function. Look at Peter Horvath's brilliant work, Intervals. Oh, but you have to look at it on Safari, precisely because of this type of issue.

Stormey
A: 

So I have this same issue, and the whole Blank and size specs are not the solution because I was already including them, and they don't override the tab thing.

What I should have is a new window that opens at a specific size so that when people click on a video link the video pops up in its own little appropriately sized window above the main page, but instead, the page pops up as a new tab and re-sizes all the other tabs to match it, super annoying.

I also tried adding in the modal=yes,alwaysRaised=yes" segment with no luck. Here is the code I am using that is not working. It has a combination of all the suggestions on here so none of them seem to work. I also tried pulling out segments to try alone with no luck. Some of the code may be seems redundant, but I am using this on a page that is within an iframe so when I remove the extra blank or returnfalse on the outside of the window open than it reverts to opening in the iframe. I have been testing the original page outside of its iframe though so the iframe isn't at fault.

Here is my unsuccessful attempt. Any suggestions are appreciated. This is after cobbling together extra bits from the suggestions in the thread.

Originally I was using the following:

Stormey