0

I am using the below to open a new window, but it seems that the options are ignored.

var newWindow = window.open('index.php?ident=' + gender + '&nick=' + nickname + '', 'PopupChat', 'directories=no,location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=yes,status=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

I have tested using Chrome, I still get an address bar etc.

Jack
  • 515
  • 1
  • 5
  • 17
  • 1
    What are the values in `w`, `h`, `top`, and `left`? – T.J. Crowder Aug 17 '15 at 16:41
  • They're numerical, width, height etc. – Jack Aug 17 '15 at 16:45
  • 2
    According to [this answer](http://stackoverflow.com/a/15230172/560593), you cannot remove the address bar in most modern browsers now, for security reasons. – Patrick Evans Aug 17 '15 at 16:45
  • 2
    Modern browsers are very limited on what you can do with window.open. If the window size is too small or the window is positioned off the screen, than the browser is most likely going to ignore it. – epascarello Aug 17 '15 at 17:03
  • possible duplicate of [Open new popup window without address bars in firefox & IE](http://stackoverflow.com/questions/2909645/open-new-popup-window-without-address-bars-in-firefox-ie) – Stephen P Aug 17 '15 at 19:27
  • On top of the limitations now present in modern browsers, I have always configured my browser to ignore most of those options, always, regardless of security concerns. You Will Not Hide My Address Bar, Evar. – Stephen P Aug 17 '15 at 19:30

1 Answers1

1

Historically, browsers have been incredibly picky about the options string, and spaces are/were not allowed. You have spaces before some of the options:

var newWindow = window.open('index.php?ident=' + gender + '&nick=' + nickname + '', 'PopupChat', 'directories=no,location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=yes,status=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Here --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^----------------^-----------------^----------------^

From MDN:

The string must not contain any whitespace

Removing them may solve the problem.

Separately, if the values in w, h, top, and left are anything but raw numbers, they'll cause trouble as well.

Working example: If I put this on a server and run it with Chrome (or Firefox or IE11), it opens Stack Overflow in a window with the options requested (except addressbar, which you can't suppress anymore):

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Foo</title>
</head>
<body>
  <input type="button" id="the-button" value="Click me">
<script>
  var w = 400, h = 600; top = 1, left = 1;
  document.getElementById("the-button").onclick = function() {
    var newWindow = window.open('http://stackoverflow.com', 'PopupChat', 'directories=no,location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=yes,status=no,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left);
  };
</script>
</body>
</html>
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Removed spaces but options are still ignored, even the title isn't set, it just shows the long URL in Chrome title. – Jack Aug 17 '15 at 16:46
  • @Jack: Strange, it works for me, see the working example above (couldn't do it as a Stack Snippet; they don't allow `window.open`). Note that the window cannot be too small. – T.J. Crowder Aug 17 '15 at 17:36