开发者

Making a Chrome extension to download (not view) the link and with custom filename

开发者 https://www.devze.com 2023-03-02 14:02 出处:网络
I\'m currently developing a simple javascript extension for Chrome. The problem is simple but probably unfixable, but still here\'s the issue:

I'm currently developing a simple javascript extension for Chrome. The problem is simple but probably unfixable, but still here's the issue:

on particular pages, i embed links to some files (i don't开发者_开发技巧 have access to server, so i can't change the way they are outputted) - a simple <a>nchor tag. then, what i'm trying to achieve is:

  1. set a filename of downloaded file (right now it's like 87sfhkjhsf and without extension)

  2. make the browser download (not view) the file in any case (right now, if it's a pdf, it gets viewed.. or if it's an mp3 it gets played with native Chrome player)

i would even accept a .dll solution IF it will really work (i even tried using Flash with FileReference.download method, but it doesn't allow to download files from other domains)

seeking help from you guys :)


In or to programmatically download a file using javascript in chrome you (currently) need either a server to bounce the download off, to be satisfied with garbled filenames (using blobbuilder; this sounds like what you are doing), or a NPAPI plugin (such as a custom .dll or Flash).

If you look at the screenshot extensions, the most popular ones use NPAPI.

I plan on using NPAPI myself, but haven't gotten around to coding for all 3 OSes yet. (I am the developer of Smooth Gestures, and have gotten many requests for a image download gesture)

All this said, there is constant development on filesystem access for javascript and a native API may become available. But I wouldn't hold my breath.

0

精彩评论

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

关注公众号