当强制通过window.location下载时,如何在JavaScript中设置blob文件的名称?
function newFile(data) {
var json = JSON.stringify(data);
var blob = new Blob([json], {type: "octet/stream"});
var url = window.URL.createObjectURL(blob);
window.location.assign(url);
}
Run Code Online (Sandbox Code Playgroud)
运行上面的代码会立即下载文件而不会刷新页面,如下所示:
bfefe410-8d9c-4883-86c5-d76c50a24a1d
我想将文件名设置为my-download.json.
我遇到一个问题,在JavaScript中引用的字符串中有一个结束脚本标记,它正在查杀脚本.我认为这不是预期的行为.这方面的一个例子可以在这里看到:http://jsbin.com/oqepe/edit
我感兴趣的测试用例浏览器:Mozilla/5.0(X11; U; Linux i686; en-US; rv:1.9.1.4)Gecko/20091028 Ubuntu/9.10(karmic)Firefox/3.5.4.
我需要打印PDF ...但是我收到错误
有解决方法吗?我只需要点击一下即可打印PDF文件
Uncaught SecurityError: Blocked a frame with origin "https://secure.domain.com" from accessing a frame with origin "https://cdn.domain.com". Protocols, domains, and ports must match.
Run Code Online (Sandbox Code Playgroud)
var iframe = $('<iframe src="'+url+'" style="display:none"></iframe>').appendTo($('#main')).load(function(){
iframe.get(0).contentWindow.print();
});
Run Code Online (Sandbox Code Playgroud)