Search code examples
javascripthtmlwindow.open

window.open opens link in new window and on original page


I am trying to create a link that opens a remote website page in a pop-up. I did a bit of googling, and came up with the following code:

<a href="http://www.yandasmusic.com" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=400')" >A pop-up link</a>

This code does open up the specified page in a new window, but for some reason it also loads the page on the original window. How can I change this code so that the pop-up opens the specified page, but does not change the page of the original window?

Thanks - Alex


Solution

  • Add return false; at the end of the onclick

    <a href="http://www.yandasmusic.com" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=400'); return false;">A pop-up link</a>