Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用javascript设置下载文件的下载名称_Javascript_Google Chrome - Fatal编程技术网

无法使用javascript设置下载文件的下载名称

无法使用javascript设置下载文件的下载名称,javascript,google-chrome,Javascript,Google Chrome,我使用javascript让人们下载他们在谷歌地图上生成的gpx文件。这是下载功能的代码 function download(filename, text) { var pom = document.createElement('a'); pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); pom.setAttribute('download', fi

我使用javascript让人们下载他们在谷歌地图上生成的gpx文件。这是下载功能的代码

function download(filename, text) {
    var pom = document.createElement('a');
    pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    pom.setAttribute('download', filename);
    console.log(pom['download']);
    pom.click();
}

文件名设置正确,但没有显示在google chrome only download.txt中。它在过去是有效的,在firefox中也是有效的,但在google chrome中不再有效。

这似乎是对下载属性工作方式的跨源更改,或者是一个普通的老错误。这已经出现在谷歌论坛上了,但是就像论坛的帖子显示的那样,相对URL

现在,这个bug还是很新的,我认为没有人确切知道为什么会发生这种情况,但可能是因为跨来源的考虑而做出了改变

编辑:这已被删除