We help IT Professionals succeed at work.

closing a window on a webpage with javascript

I have this bit of code on an exit button on a webpage

<div style="position:absolute; left:690; top:3; cursor:hand;">
<a href="JavaScript:window.close()">
<img src="exit_course_n.gif"  onMouseOver="src='exit_course_o.gif'"
onMouseOut="src='exit_course_n.gif'"  border="0" >
</a>
</div>

This works fine to close the window when you first come into it. HOWEVER the html page opens another html page in that window when I click a "go to" button. On this new page there is a "return to menu" button which opens up the original webpage in that window again. So all in one window, no new window. When I am back on the original webpage, the window.close above code ^^ doesn't work. I tried self.close as well - same problem. Could anybody give me some code that would work?

thanks.

Comment
Watch Question

erikTsomikSystem Architect, CF programmer

Commented:
can you post more code here
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008

Commented:
>> the html page opens another html page in that window when I click a "go to" button
Are you working with frames?

Commented:
Just a shot in the dark without seeing more of your code, but maybe try something like the following...
<div style="position:absolute; left:690; top:3; cursor:hand;" onClick="JavaScript:window.close()">
<img src="exit_course_n.gif"  onMouseOver="src='exit_course_o.gif'"
onMouseOut="src='exit_course_n.gif'"  border="0" >
</div>

Open in new window

CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
My guess would be:
<div style="position:absolute; left:690; top:3; cursor:hand;">
<a href="#" onclick="JavaScript: top.close();return false;">
<img src="exit_course_n.gif"  onMouseOver="src='exit_course_o.gif'"
onMouseOut="src='exit_course_n.gif'"  border="0" >
</a>
</div>

Open in new window

<BODY onUnload = "parent.close();widow.close()">  works for me.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.