首页 > 解决方案 > 注入的 JS 可以将点击下载的文件重定向到预定义的文件路径吗?

问题描述

我正在尝试编写一个 Chrome 扩展程序,当单击一个按钮时,它会下载一个您通常从现有站点上的另一个按钮获取的文件,而是自动将其下载到用户定义的文件路径。到目前为止,我只在文件来自的按钮上调用 click() 。我需要将该文件下载到内存文件路径中。谢谢!

popup.js:

extensionBtn.onclick = function(element) {
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
    chrome.tabs.executeScript(
      tabs[0].id,
      {file: "content_script.js"});
    });
};

content_script.js:

function clickGpxDownload() {
    //Where I'd want the file to instead be downloaded to
    var filePath = "C:/foo/bar"

    //Button the file comes from
    var gpxDownload = document.getElementById("ctl00_ContentBody_btnGPXDL");

    gpxDownload.click();
}

clickGpxDownload();

标签: javascriptgoogle-chrome-extension

解决方案


推荐阅读