最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome Extensions onDeterminingFilename syntax - Stack Overflow

programmeradmin3浏览0评论

I have created a simple extension for use on a clients pc to add a save image option to the context menu. Googles Chrome extension documentation, plus examples quoted on the web, leads me to believe I can specify a subdirectory of the 'Downloads' folder as the download target, using 'filename' in the 'onDeterminingFilename' Event.

But I can't figure the syntax. Heres the listener with my pseudo code after 'filename':

chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
suggest({filename: mysubdirectory + item.filename});
});

I've tried including mysubdirectory in quotes and with escaped characters, but with no change. The listener works as I've used filename: 'new name' to test it. I'm sure is very very simple, or maybe I've misunderstood the Event. Thanks.

I have created a simple extension for use on a clients pc to add a save image option to the context menu. Googles Chrome extension documentation, plus examples quoted on the web, leads me to believe I can specify a subdirectory of the 'Downloads' folder as the download target, using 'filename' in the 'onDeterminingFilename' Event.

But I can't figure the syntax. Heres the listener with my pseudo code after 'filename':

chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
suggest({filename: mysubdirectory + item.filename});
});

I've tried including mysubdirectory in quotes and with escaped characters, but with no change. The listener works as I've used filename: 'new name' to test it. I'm sure is very very simple, or maybe I've misunderstood the Event. Thanks.

Share Improve this question asked Feb 10, 2014 at 13:31 user3292967user3292967 1411 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

I'd used the wrong quote marks.

This works:

chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
suggest({filename: "mysubdirectory/" + item.filename});
});

If mysubdirectory is not present it's created. If it is present, the item is added, plus any other items downloaded. Happy days.

发布评论

评论列表(0)

  1. 暂无评论