SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Kill Window Handler?

    Here's a quickie.

    I've got a few pages that allow someone to change the contents of their database. What I've done is written a little javascript function that checks to see if the user changes anything. If he or she HAS changed something and tries to exit the page without clicking "UPDATE", he or she is faced with a pop-up window saying: "You wanna register the changes?" or something like it.

    Here's my question: does Javascript give control over the browser window's close button? As is, the script described above only kicks into action when the user clicks away from the current window. I'd like it to run even if the user tries to kill the window.

    Man, for a quick question that was sure longwinded...!

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can stop the window from closing, but you can capture the unload event, open a new window and then post the form to this window:

    Code:
    window.onunload = function(){if(confirm("Post form?")){postForm(frm)};}
    function postForm(frm)
    {
      var w = window.open('', 'w', 'width=100,height=100');
      frm.target='w';
      frm.submit();			
    }
    Another solution is; open the "change db contents" page in a frameless window .
    No frame => no X buttton!
    (but Alt + F4 can close the window of course...)

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does NS4 support chromeless windows? i dont think so..if it does, im changing my site!
    InQuE

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works in NS 4.03, 4.51 & 6.2 and Mozilla 1.0
    Code:
    <html>
      <head>
        <script language="JavaScript">
          var w = null; 
          function popup()
          {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
            w = window.open('','','titlebar=no,width=100,height=100');
            netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserWrite");
          }
        </script>
      </head>
      <body>
        <a href="javascript://" onclick="popup();">Open Popup</a>
        <a href="javascript://" onclick="w.close();">Close Popup</a>
      </body>
    </html>
    Last edited by jofa; Aug 25, 2002 at 15:16.

  5. #5
    SitePoint Zealot jonsteele's Avatar
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jofa's script does work only after a nasty security warning (not so bad in v6 or Moz).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •