javascript 下载文件,在浏览器中打开新标签页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13301695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Download file, open new tab in browser
提问by user1260827
After some actions on my site user can donwload file. First, I ask user: "Would you like to download file". This is modal dialog created with fancybox. There are buttons: Yes and No. When user clicks "Yes" I want to open new tab in browser and show standart save file dialog. I have this code:
在我的网站上进行一些操作后,用户可以下载文件。首先,我问用户:“你想下载文件吗”。这是用fancybox创建的模态对话框。有按钮:是和否。当用户单击“是”时,我想在浏览器中打开新选项卡并显示标准保存文件对话框。我有这个代码:
$(document).on('click', '#agentAcceptSave', function () {
alert(1);
window.open = '/ticket?orderId=' + $('#agentOrderId').val();
}
But, new tab not open and url not calls, but alert is showed. Where is a error?
但是,新选项卡未打开且 url 未调用,但显示警报。错误在哪里?
回答by mohammed momn
I tried this code and it worked for me:
我试过这段代码,它对我有用:
$(document).on('click', '#download', function() {
window.open('http://www.google.com');
});