是否可以从扩展程序触发Chrome自己的另存为(页面上下文菜单, Ctrl + s )对话框?或以某种方式将此 Ctrl + s 命令发送到活动选项卡?我的扩展程序在活动选项卡上进行了一些修改,然后添加一个新的"保存整个页面"按钮进入它的顶部。为避免混淆,我不想以编程方式保存任何内容或写入磁盘。我不需要chrome.pageCapture.saveAsMHTML
或chrome.downloads.download
。我只需要通过单击我的按钮打开另存为对话框,而不是手动右键单击页面并选择"另存为"。这只是我的需求的私人扩展,所以任何有效的解决方案都可以。
我有content_script
(content.js)和background
(background.js):
// part of my background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.message === "adatlap_savehtml") {
// open Save As dialog (CTRL+S) for savaing files (html, images) separately
}
}
);
和
// part of my content.js
$btnSaveHtml.click(function() {
// this could be useles if the Save As dialog can be opened here.. (?)
chrome.runtime.sendMessage({"message": "adatlap_savehtml"});
});
提前致谢!