Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q407 When I use a normal text link to open a popup window the main window is also affected - how do I avoid this?

You are here: irt.org | FAQ | JavaScript | Window | Q407 [ previous next ]

If you are attempting to load a popup window using code similar to:

<a href="javascript:window.open('test.html','windowName','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=300')">test</a>

Then change it to:

<script language="JavaScript"><!--
function myopen(filename,windowname,properties) {
    mywindow = window.open(filename,windowname,properties);
}
//--></script>

<a href="javascript:myopen('test.html','windowName','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=300')">test</a>

The following was submitted by Dan Souza

What I use is the following: It always works for me. Substitute your own url of course. Using return false prevents the browser's main window from going to the url and using the url in the <a href= allows a non javascript enabled browser to go to the url

<a href="yoururl" onClick="window.open('yoururl.html'); return false">Your Link Text</a>

Feedback on 'Q407 When I use a normal text link to open a popup window the main window is also affected - how do I avoid this?'

©2018 Martin Webb