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

Close window on click

P: 16
Hi!
Hi i have created a webpage which is like a game. what i'm stuck on now is that there is a webpage called "pageA" and there is an image on it. if anyone clicks that image, a alert box should appear saying " Game Over" with ok button and when that ok button is clicked "pageA" should be closed as well.
a href="javascript:window.close()" wouldnt suit me bcs it has a builtin message already and i cant edit. Can anyone suggest me a way to do it. thx
Oct 22 '07 #1
Share this Question
Share on Google+
6 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

simply use a function ... for example:

Expand|Select|Wrap|Line Numbers
  1. function game_over() {
  2.     alert('whatever message');
  3.     window.close();
  4. }
call that on click of your image.

kind regards
Oct 22 '07 #2

P: 16
Thx! but only problem is that the automated message "The web page you are viewing is trying to close. Do you want to close this window".. appears no matter wat. How can i not have that and close "pageA".

simply use a function ... for example:

Expand|Select|Wrap|Line Numbers
  1. function game_over() {
  2.     alert('whatever message');
  3.     window.close();
  4. }
call that on click of your image.

kind regards[/quote]
Oct 22 '07 #3

gits
Expert Mod 5K+
P: 5,390
in case you want to close the main browser window ... you cannot avoid that ... but you may redirect the user to another page if you prefer ...

kind regards
Oct 23 '07 #4

P: 16
in case you want to close the main browser window ... you cannot avoid that ... but you may redirect the user to another page if you prefer ...

kind regards

Oh ya. that sounds like a good idea. but could the user be able to use the back button and go back to the main page. i wouldnt want that. but still if i want to redirect how would i do that. ill do the research in the mean time. if u can help that'll be awosome. thx a lot.
Oct 24 '07 #5

gits
Expert Mod 5K+
P: 5,390
the following should do the trick ... it replaces the current uri in the browserwindow and the history ...

Expand|Select|Wrap|Line Numbers
  1. function game_over() {
  2.     alert('whatever message');
  3.     window.location.replace('your_uri');
  4. }
kind regards
Oct 24 '07 #6

Ferris
100+
P: 101
Hi:

there's a sollution in IE,but not in firefox.
javascript can only close the window which is opened by javascript. when you want to close a window whch is not opened by javascript,you will get an confirm message in IE, but nothing in Firefox.

try these code (I test them in IE7):

[HTML]
function game_over() {
alert('whatever message');

window.parent.opener=null;
window.open('','_parent');
window.parent.close();
}
[/HTML]


hope it helps.
Oct 24 '07 #7

Post your reply

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