Close window on click

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mayormel
    New Member
    • Oct 2007
    • 16

    Close window on click

    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="javascrip t: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
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    simply use a function ... for example:

    [CODE=javascript]function game_over() {
    alert('whatever message');
    window.close();
    }[/CODE]
    call that on click of your image.

    kind regards

    Comment

    • mayormel
      New Member
      • Oct 2007
      • 16

      #3
      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:

      [CODE=javascript]function game_over() {
      alert('whatever message');
      window.close();
      }[/CODE]
      call that on click of your image.

      kind regards[/QUOTE]

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        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

        Comment

        • mayormel
          New Member
          • Oct 2007
          • 16

          #5
          Originally posted by gits
          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.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            the following should do the trick ... it replaces the current uri in the browserwindow and the history ...

            [CODE=javascript]function game_over() {
            alert('whatever message');
            window.location .replace('your_ uri');
            }[/CODE]
            kind regards

            Comment

            • Ferris
              New Member
              • Oct 2007
              • 101

              #7
              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.o pener=null;
              window.open('', '_parent');
              window.parent.c lose();
              }
              [/HTML]


              hope it helps.

              Comment

              Working...