Pregunta

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

¿Fue útil?

Solución

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>

Otros consejos

Just add return false , Because the default action is true always.

The return value of an event handler determines whether or not the default browser behavior should take place as well. In the case of clicking on links, this would be following the link, but the difference is most noticeable in form submit handlers, where you can cancel a form submission if the user has made a mistake entering the information.

change

<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>

with

<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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top