...

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



Nadabrahma
04-19-2005, 12:06 AM
Hi!
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. :)

_Aerospace_Eng_
04-19-2005, 12:41 AM
This should give an idea

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

<body>
<a href="#" onclick="openWin();return false">link</a>
</body>
</html>
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>

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

function doOpen(url, target){
var w = window.open(url, target, 'width=800, height=600, resizable=1');
w.focus();
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";
opener.focus();
}
window.close();
return false;
}
...
<input type="button" value="Close" onclick="closeMe()" />
or:
<a href="#" onclick="return closeMe()">Close</a>

Nadabrahma
04-19-2005, 12:50 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum