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).
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?
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.
Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com
You can overload the window.location...You can use somehow,
//avoid onbeforeonload here
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)