By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,599 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,599 IT Pros & Developers. It's quick & easy.

window.close() not working

P: 60
Hi

In my php page i'm having a close image button. Onclick , i'm trying to close the
current browser window. It is not working.
<img src = image_close.jpg onClick="window.close()">

Pls post your replies

Thanks in advance
somaskarthic
Aug 28 '06 #1
Share this Question
Share on Google+
5 Replies


100+
P: 268
Try this

<img src = image_close.jpg onClick="javascript:window.close()">
Aug 28 '06 #2

Banfa
Expert Mod 5K+
P: 8,916
window.close()

only works if you opened then window in the first place, you can not close a window opened by the user.
Aug 28 '06 #3

P: 13
Hi

In my php page i'm having a close image button. Onclick , i'm trying to close the
current browser window. It is not working.
<img src = image_close.jpg onClick="window.close()">

Pls post your replies

Thanks in advance
somaskarthic
If you are echoing it , make sure that echo has echo ' text '; and not echo " text ";

If the close doesnt works , try javascript:exit()

Kind Regards,
Rahul Agrawal
Web2003 Corporation
Sep 4 '06 #4

100+
P: 268
hai can you please send your code

Thanks
Vssp
Sep 4 '06 #5

P: 1
This might help anyone trying to add a "window.close" button to an echoed page (the usual javascript doesn't work with a php echo)... note the single quotes for the echo...

echo '<div id="myDiv">
<p>Bit of content etc. etc.</p>
<script language="javascript" type="text/javascript">
function closeWindow() {window.open("","_parent","");
window.close();}</script>
<input type="button" onclick="closeWindow();" value="Close Window" title="Close window">
</div>';

hope it helps... not tried it in all browsers yet!
Dec 16 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.