www.webdeveloper.com
Results 1 to 3 of 3

Thread: Get target url from "window.onbeforeunload"?

  1. #1
    Join Date
    Apr 2010
    Posts
    7

    Get target url from "window.onbeforeunload"?

    First of all, before the question I'll do the justification - because I realise this is a sensitive "no no" private area of the user's browsing experience. I only need/want to be able to capture the target url's from my own domain (well actually only a single one, against a string match).

    The question:
    On my site I use "window.onbeforeunload" to give a confirmation that the user wants to leave the site when they're doing something which will be interrupted by leaving the site.
    The problem is that when a user requests a certain file to download, I use "window.location" to point to the PHP script which in-turn starts the file download.
    Now, the user's browser never actually changes pages, but because I'm launching the download through "window.location" it's triggering the "window.onbeforeunload". Is there any way that I can detect that I'm requesting the download (like matching the script name in the target url?) and then not show the leaving confirmation?

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    use iframe.src or iFrame.contentWindow.location instead of window.location=...

    a <body> onclick handler should tell when a link's clicked, and based upon the href, you can suppress onbeforeunload.

  3. #3
    Join Date
    Dec 2010
    Location
    Romania
    Posts
    27
    You can overload the window.location...You can use somehow,
    Code:
    window.location=function()
    {
      //avoid onbeforeonload here 
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles