开发者

Open/Save as dialog box

开发者 https://www.devze.com 2022-12-17 22:23 出处:网络
Jquery: Is there a way to catch the event that is fired when the browser opens the Open/ Save开发者_StackOverflow as dialog box?

Jquery:

Is there a way to catch the event that is fired when the browser opens the Open/ Save开发者_StackOverflow as dialog box? Open/Save dialog example http://qpack.orcanos.com/helpcenter/Images/openSave.png

I need to do something when the dialog is shown.


Not possible. The browser handles this specifically so that web hackers can't force you to download a virus, which would be much easier for them if it happened in javascript.


A i know there is no particular way to detect when this window appears. Try to add click handler on the download button/icon. Or as i solved this on my project - i added async logic. when document was generated, i passed 'succes' to client, and then JS code made some logic i needed.


Not that I am aware.

I'm guessing that this will be opened when you click some item on the page. You best bet is to capture that event.

Given your anchor:

<a id="MyLink" href="MyDoc.doc">

A simple click handkler will intercept this event, before the above box pops up

$(document).ready(function(){
    $("#MyLink").click(function() {
        alert($(this).length);
    });
});


As far as I know, there is no way to do that.


Is it always the same file type that you are checking for? If so, you could do something like

$("a").click(function(e){
   var extension = $(this).attr("href").substr($(this).attr("src").lastIndexOf("."));
   if ((extension && /^(zip|vbd)$/.test(extension))){
      alert("Hi now you can do whatever you needed to do!");
   }
});

Note no e.preventDefault(), since you still want the prompt to come up I am presuming?

File extension check snippet


You might want to check out OpenSave:

http://www.gieson.com/Library/projects/utilities/opensave/

It's not really part of jQuery, but you can probably integrate it easily. Looks like they're using Flash to overcome the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消