View Full Version : Link in Javascript window: close window + open new doc in reg. window

04-18-2005, 11:06 PM
I need help with this little problem:
A presentation opens in a Javascript window. In that window, I want a link that does two things:
1. closes the Javascript window
2. opens a new document in the parent window (=the regular browser window which had the link that opened the js. window.)

To get either one of these things done is easy; the hard part for me is getting both things done with one mouse click.
And, of course, the whole thing should be cross-browser compatible...
I really don't know much about javascript, so I use scripts from places like Dynamic Drive. :)

04-18-2005, 11:41 PM
This should give an idea

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function openWin(){
newwin.document.write('<a href="#" onclick="opener.window.location=\'http://www.codingforums.com\';window.close();return false">close me</a>');

<a href="#" onclick="openWin();return false">link</a>
if you are going to have this popup page already made, then just put this link in it

<a href="#" onclick="opener.window.location=\'http://www.codingforums.com\';window.close();return false">close me</a>

04-19-2005, 03:59 AM
main page:

function doOpen(url, target){
var w = window.open(url, target, 'width=800, height=600, resizable=1');
return false;
<a href="popup.htm" target="mypopup" onclick="return doOpen(this.href, this.target)">popup</a>

popup page:

function closeMe(){
if (opener && !opener.closed){ //ensures that opener is still open
opener.location.href = "newpage.htm";
return false;
<input type="button" value="Close" onclick="closeMe()" />
<a href="#" onclick="return closeMe()">Close</a>

04-19-2005, 11:50 AM
Many thanx to both of you guys!
Really fantastic to get such good help for free!

Yes, I already have a very good popup-script which centers the popup.
So all I needed was the closing-code.

The one supplied by glenngv proved easiest to handle in my hands.

Again, many thanx!