Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add a link that closes the window? 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
Hi,

When people have sent a form submission on my site I display a "thankyou" window which is a new instance of the browser window. I want to have a "Close" link that they can click to close the window - how do I do it please?

Thanks in advance,

- Andy
_______________________________
"On a clear disk you can seek forever"
 
if the window was opened via script, then

<a href=&quot;#&quot; onclick=&quot;window.close();&quot;>close</a>

if the window was NOT opened via script, then this typically works in IE5.5+, NS6+, Moz (except latest MozFirebird)

<a href=&quot;#&quot; onclick=&quot;window.opener = self; window.close();&quot;>close</a>


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
You need to apply the knowledge that you already have. Read back your own question and fill in the blanks.

I need a link
Code:
<A .... >

that they can click to close the window
Code:
<A onClick=&quot;window.close()&quot;>Close</A>

I'm sorry for being a dumb-ass, but it was almost funny how you asked for something and the answer was in your question. [yoda]

Einstein47
(&quot;Vision without action is a daydream - Action without vision is a nightmare. Japanese Proverb&quot;)
 
Thanks both.

I appreciate the candour Einstein47, which is applicable to anyone who has an iota of an idea about what they're doing, which excludes me.


- Andy
_______________________________
&quot;On a clear disk you can seek forever&quot;
 
...however...

Jemminger gets the star because his solution doesn't pop up a message box asking if the user wants to close the window...

- Andy
_______________________________
&quot;On a clear disk you can seek forever&quot;
 
You can also just use <A HREF=&quot;javascript:window.close()&quot;>Close Window</A>

You don't need to use onClick

Nate

mainframe.gif

 
SPYDERIX,

you should never use the &quot;javascript:&quot; pseudo-protocol in a hyperlink because:

1. if you try to use your browser's &quot;open in new window&quot; function, it won't work.
2. if you try to bookmark or save the link to favorites, it won't work.



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
I like to wrap the close window instructions in a if statement to make sure the browser supports it. If the browser doesn't support it they don't see the words &quot;Close Window&quot;

<script type=&quot;text/javascript&quot; language=&quot;JavaScript1.2&quot;> if (document.close) { document.write('<a href=&quot;javascript:self.close()&quot;><nobr>Close Window</nobr></a>') }
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top