Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Window | Q407 [ previous next ]

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

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


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.