Forum Moderators: open

Message Too Old, No Replies

A popup window that doesn't scroll the original page back to the top?

         

chuckee

4:41 am on Aug 15, 2007 (gmt 0)

10+ Year Member



Hi,
I have a webpage that uses the following code to open a popup window once a link is clicked. The problem is that the original webpage is immediately scrolled all the way back up to the top. How can I stop this from happening?

<a href="#" onClick=" window.open('terms.html','mywindow','width=600,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes')">terms and conditions</a>

Cheers!

daveVk

6:50 am on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try

<a href="#" onClick=" window.open('terms.html','mywindow','width=600,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');return false;">terms and conditions</a>

The "return false;" should prevent the normal action of going to href="#"

chuckee

7:32 am on Aug 15, 2007 (gmt 0)

10+ Year Member



Thanks Dave! That works perfectly.

vincevincevince

8:10 am on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My preference is to change href="#" into href="javascript://"

Achernar

10:27 am on Aug 15, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



href="javascript:;" is even better. :)

daveVk

1:03 am on Aug 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or

href="javascript:window.open( etc

and no OnClick?

vincevincevince

3:33 am on Aug 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Technically speaking, I think that return false; is the more proper method as it allows you to keep your href="" for accessibility or old browsers, e.g.:

<a href="info.html" target="_blank" onClick="showpopup();return false">popup</a>

or
<a href="faq.html#33" onClick="ajax_get_faq(33);return false;">Why is the sea red?</a>

Achernar

10:20 am on Aug 17, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



I use both solutions. When the link can be visited without javascript, I put the full url in href and "return false" in onclick. If the page is only available with javascript, I put "javascript:;" in href to inform the user.