65

I have been working on a web app and for part of it I need to open a new window. I have this working on all browsers, my sticking point is with Google Chrome.

Chrome seems to ignore the window features which is causing me issues, the thing I'm struggling with is I need the address bar to be editable within the new window. FF, IE, Safari and Opera do this fine, Chrome does not.

My Code:

function popitup(url) {
  newwindow=window.open(url, 'name', 'toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=1,resizable=1,width=800,height=600');
  if (window.focus) {
    newwindow.focus()
  }
  return false;
}
beaver
  • 523
  • 1
  • 9
  • 20
Paul
  • 1,025
  • 1
  • 7
  • 16
  • 1
    Wow - that's pretty weird. Some kind of misguided 'security' feature, I imagine. – Ray Apr 03 '10 at 19:48
  • yeah its an odd one, took some working to get this far! lol – Paul Apr 03 '10 at 19:49
  • 3
    This probably isn't what you want to hear, but don't open things in new windows/tabs. If the user wanted a new window, they can ask their browser to do it. – jamesdlin Apr 03 '10 at 19:56
  • 12
    thanks jamesdlin, its actually a web dev tool for testing browser sizes so its kinda essential :) – Paul Apr 03 '10 at 20:12
  • check this question http://stackoverflow.com/questions/4994063/setting-the-page-title-of-chrome-window-open – Mahmoud Farahat Mar 19 '11 at 09:41
  • The behavior also depends on where your `popitup` funtion is called from, which probably causes the confusion. See my answer below. – Jeroen Ooms Jan 07 '14 at 05:25

9 Answers9

37

The other answers are outdated. The behavior of Chrome for window.open depends on where it is called from. See also this topic.

When window.open is called from a handler that was triggered though a user action (e.g. onclick event), it will behave similar as <a target="_blank">, which by default opens in a new tab. However if window.open is called elsewhere, Chrome ignores other arguments and always opens a new window with a non-editable address bar.

This looks like some kind of security measure, although the rationale behind it is not completely clear.

Community
  • 1
  • 1
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
26

This worked for me:

newwindow = window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=800, height=900, top=10, left=10");
surlac
  • 2,961
  • 2
  • 22
  • 31
Ben
  • 261
  • 3
  • 2
  • 1
    It depends on where it is called from, see my answer below. – Jeroen Ooms Jan 07 '14 at 05:23
  • isn't working for me with a named window (it's opening a new window rather than an existing one), regardless of where it's being called from @jeroen – charley Nov 13 '17 at 15:55
9

The location=1 part should enable an editable location bar.

As a side note, you can drop the language="javascript" attribute from your script as it is now deprecated.

update:

Setting the statusbar=1 to the correct parameter status=1 works for me

scunliffe
  • 62,582
  • 25
  • 126
  • 161
  • thanks for the reply scunliffe :) I just tried with those settings and the location bar displays the URL but still cannot be edited :( – Paul Apr 03 '10 at 20:11
  • 1
    Thanks - I was missing the status=1 part of the params, and that had prevented chrome from treating it as a full-featured window.open(). When I put it in, it started opening windows in tabs. – Tom Lianza Mar 03 '11 at 02:00
5

menubar must no, or 0, for Google Chrome to open in new window instead of tab.

Tim Murphy
  • 4,892
  • 4
  • 40
  • 48
  • This solution works in Google Chrome 29/Opera 20, although positioning windows in these two browsers (using "left=XX&top=YY") doesn't work as expected. (assumed to be a bug in both of these browsers) – Algy Taylor Apr 08 '14 at 12:06
5

I believe currently there is no javascript way to force chrome to open as a new window in tab mode. A ticket has been submitted as in here Pop-ups to show as tab by default. But the user can click the chrome icon on the top left corner and select "Show as tab", the address bar then becomes editable.

A similar question asked in javascript open in a new window not tab.

Community
  • 1
  • 1
Dingle
  • 2,402
  • 19
  • 12
  • If you don't specify and window properties when you open a window, it should put it in a tab. Conversely, if you want a window to open instead of a tab, specify at least one window property. – nickytonline Apr 26 '10 at 16:06
  • 1
    The OP's problem is not about opening as a new window or tab. In chrome, OP is opening a new window, but the location bar is grayed out. The address bar is only editable when the new window is "show as tab". – Dingle Apr 26 '10 at 18:34
  • thanks for the input Dingle, I might be able to work around that somehow ;) – Paul Apr 29 '10 at 14:55
  • @McBonio, Please update the post with your workaround method, thanks. – Dingle Apr 29 '10 at 18:20
3

As far as I can tell, chrome doesn't work properly if you are referencing localhost (say, you're developing a site locally)

This works:

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup() {
  windowObjectReference = window.open("http://www.cnn.com/", "CNN_WindowName", strWindowFeatures);
}

This does not work

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup() {
  windowObjectReference = window.open("http://localhost/webappFolder/MapViewer.do", "CNN_WindowName", strWindowFeatures);
}

This also does not work, when loaded from http://localhost/webappFolder/Landing.do

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup() {
  windowObjectReference = window.open("/webappFolder/MapViewer.do", "CNN_WindowName", strWindowFeatures);
}
charley
  • 124
  • 1
  • 5
2

Don't put a name for target window when you use window.open("","NAME",....)

If you do it you can only open it once. Use _blank, etc instead of.

Pedro
  • 75
  • 6
0

Why is this still so complicated in 2021? For me I wanted to open in a new chrome window fullscreen so I used the below:

window.open("http://my.url.com", "", "fullscreen=yes");

This worked as exepected opening a new chrome window. Without the options at the end it will only open a new tab

Liam Middleton
  • 280
  • 3
  • 7
-3

I have the same problem, Chrome doesn`t open a new window from code (not handlers).
I found this solution:

setTimeout(function () {
    window.open(
        url, 'name', 'toolbar=1, scrollbars=1, location=1,
        statusbar=0, menubar=1, resizable=1, width=800, height=600'
    );
}, 1);
barsmaga
  • 155
  • 1
  • 7
  • 2
    @cezar This is not a new question. Note the part that says "I found a this solution". – showdev Dec 19 '17 at 22:17
  • This creates an infinite loop. Moreover, it opens a new tab as opposed to a new window. – raksheetbhat Mar 18 '18 at 16:58
  • Sorry. I am confused with two functions (SetInterval and SetTimeout), this is the solution that works with both, but SetInterval its realy infinity loop. As resut solution with SetInterval funtion it is wrong way, try use SetTimeout function for use this workaroun – barsmaga Mar 19 '18 at 19:27