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

Q1807 How do I get a child window to close after clicking on a link that opens in the parent window?

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

Q1807 How do I get a child window to close after clicking on a link that opens in the parent window?

A spawned child window contains a link that is supposed to open in the parent, then the child is supposed to close. This is similar to the Javascript:Windows FAQ 84, yet decidedly different.

A simple onclick="window.close" won't work in this case because the window will close before it has a chance to process the link. So, use the code for FAQ 84 and attach a window.close to the end. This forces the child to think about what he's done and process the link before closing.

<head>:
<script language="JavaScript"><!--
function load(file,target) {
  if (target != '') {
    target.window.location.href = file;
  } else {
    window.location.href = file;
  }
  window.close();
}
//--></script>

The link:
<a href="javascript:load('thelink.html',opener)">

Submitted by Dan


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.