Because the page is locked, you can't do anything with JavaScript, because it is locked as well.
But, what are you trying to do? Are you trying to somehow log the fact that the user is downloading the file? If yes, there are better ways to do it, and they're on the server-side. Use some server-side scripting language to serve the file and log the fact that it was downloaded.
If that's not what you're trying to do, then the only way is using either onclick
on the link or onunload
/onbeforeunload
, but these are less reliable and I am sure that you will find completely different behavior on different browsers.
Actually, now that I think of it, there is one more way, but it's very dirty. The idea is to set an interval to run every second and check if between two runs more than a second has passed. Something like:
var lastTime = new Date().getTime();
function checkTime() {
var curTime = new Date().getTime();
if (curTime - lastTime > 1100) { // 1100 because there might be small browser lags
// do something after the dialog appeared and the user did something with it
}
lastTime = curTime;
}
setInterval(checkTime, 1000);
Please note, that there are browsers (Chrome is an example, I think) that do not block the page while that dialog is opened, so this might not work. Make sure to double-cross-check everything if you go about using this.
I have to go take a shower now.