6

I am trying to open new window without toolbars using the code below but it opens new window with the toolbars (at least in IE). Any idea what am I doing wrong?

<a href="http://www.google.com" onclick="popupWindow(this.href)" target="_blank"><img src="/myImage"/><a>

function popupWindow(url)
{
    window.open(url,"MyWindow","config='toolbar=no, menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no'");
}
Faisal Rahman Avash
  • 1,268
  • 9
  • 13
Joly
  • 3,218
  • 14
  • 44
  • 70
  • Does it matter that you spelled the "status" option at the end wrong? – Ian Oct 03 '12 at 15:44
  • 1
    Also, what do you expect the "toolbars" to mean? Take a look at https://developer.mozilla.org/en-US/docs/DOM/window.open to get all options. – Ian Oct 03 '12 at 15:45
  • 1
    The third param is just a comma-separated list of key=val pairs, not an assignment string. Remove the config='' portion of it. – AlienWebguy Oct 03 '12 at 15:49

3 Answers3

8

A quick Google search found the syntax for this at DevShed:

<script language="javascript">
function myPopup(url, windowname, w, h, x, y)
{
    window.open(url, windowname, "resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no, directories=no, width=" + w + ", height=" + h + ", left=" + x + ", top=" + y);
}
</script>

Note that it differs from your own in that you have config= as part of the last argument, and it's not needed (as AlienWebguy pointed out).

JYelton
  • 35,664
  • 27
  • 132
  • 191
3

There were several issues in your code:

  • There should be only 3 ws in wwww.google.com
  • Unnecessary config='. Also remove that final closing '.
  • atus=no should be status=no

Correcting these issues makes the pop-up work:

<a href="http://www.google.com" onclick="popupWindow(this.href)" target="_blank">Click</a>
<script type="text/javascript">
function popupWindow(url)
  {
    window.open(url,"MyWindow","toolbar=no, menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no");
  }
</script>
Dave
  • 8,163
  • 11
  • 67
  • 103
KatieK
  • 13,586
  • 17
  • 76
  • 90
  • I've corrected all this but still getting the address bar etc when the window opens. – Joly Oct 03 '12 at 19:43
  • Does your browser allow these changes? For example, FF disables this by default - see http://stackoverflow.com/questions/2909645/open-new-popup-window-without-address-bars-in-firefox-ie. – KatieK Oct 03 '12 at 20:15
  • The code I'm writing is for the company's intranet, which officially only supports IE therefore I only test it with this browser (IE8) – Joly Oct 04 '12 at 09:20
  • I think I've got something. The real URL I'm transferring to the JS function looks something like this: /irj/portal?NavigationTarget=ROLES://pcd:portal_content/hello and I'm getting "Invalid argument" in the javascript console. Perhaps I need to escape special characters in this URL? – Joly Oct 04 '12 at 10:05
  • I tried with escape(), encodeURI() and encodeURIComponent() but still getting the error above. Any ideas.....? – Joly Oct 04 '12 at 10:14
  • If you get the right result when passing http://www.google.com, but the wrong result when you're using the real URL, then it's the URL causing the problem. – KatieK Oct 04 '12 at 15:23
  • Solved it and its not the URL, for some reason in IE the name of the window has to be an empty string. So, if I rename "MyWindow" to "" it works. Strange but googling shows more people have this problem. – Joly Oct 04 '12 at 22:26
2

Thanks to everyone for replying.

The issues mentioned were typos here, they were correct on my original code.

For some reason in IE the name of the window has to be an empty string. So, if I rename "MyWindow" to "" it works. Strange but googling shows more people have this problem.

Joly
  • 3,218
  • 14
  • 44
  • 70