Click to See Complete Forum and Search --> : Newbie inquiry - Close button on second window not working.


CalifNina
06-01-2003, 12:16 PM
Hello, first post here. I'm new to JavaScript and been playing with it for just a few days now ... am at an impass. Situation is this ... From my main page I have a button to open a second window ... that code works fine and is as follows (in case you need to see it to determine problem):

Inside Main Page HEAD section:

<SCRIPT TYPE="text/javascript">
function openWindow()
{
window.open("wks2notes.html","myWindow","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory= yes,width=400,height=400")
}
</SCRIPT>

Inside Main Page BODY section:

<FORM>
<INPUT TYPE="button" VALUE="Workshop Notes" onclick="openWindow()">
</FORM>


From this, the new window comes up fine and displays the contents properly. A Close button displays at the bottom of the second window, but when depressed --> nothing happens. This is what I need to fix. Here is the code from the second window:


Inside Second window HEAD section:

<SCRIPT LANGUAGE="JavaScript">
function closeWindow()
{
myWindow.close()
}
</SCRIPT>

Inside Second window BODY section:

<FORM>
<INPUT TYPE="button" VALUE="Close Window" onclick="closeWindow()">
</FORM>

I've tried various modifications to no avail. Can someone see what I am obviously doing wrong? I do not see it. Anything anyone can offer?

Thanks so much,
~ CalifNina

Charles
06-01-2003, 12:34 PM
The trick in using JavaScript is to do things so that your page still works well for the 13% of users who do not use JavaScript. Always open a new window in such a way that the resource will appeaar in the parent window if there is no JavaScript or if new windows have been disabled.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<form action="test2.html" onsubmit="window.open(this.action, 'child', 'width=400,height=400,scrollbars,status'); return false">
<title>test.html</title>
<div>
<input type="submit" value="Workshop Notes">
</div>
</form>


And use JavaScript to only draw buttons when they will work.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>test2.html</title>
<script type="text/javascript">
<!--
document.write('<button onclick="if (self.opener) self.close()">Close Window</a>');
// -->
</script>

khalidali63
06-01-2003, 12:35 PM
change this line

myWindow.close()

to

self.close();

it will work..:-)

Charles
06-01-2003, 12:42 PM
Originally posted by khalidali63
it will work.. Not on my browser.

CalifNina
06-01-2003, 12:50 PM
Thank you for both replies!

Charles - your info is advanced for me but I get what you are saying. Good insight and rules for me to be aware of. I have copied and saved your coding. As I gain more experience I'm sure I'll have to use it.

Khalidali - your fix is at my beginner level and worked fine. I am using MIE. This will work for what I need to do.

Appreciate the help.
~ CalifNina

khalidali63
06-01-2003, 12:59 PM
You are welcome..thats what I am here for...:D

Unlike some otherss.....:p