我有一个 jQuery 模式 UI 基本上阻止用户下载文件。我使用 preventDefault
来阻止下载管理器的显示。但这会杀死GET
。
用户点击同意
后,我如何请求继续下载?
我用谷歌搜索过这个,大多数人都在做表单提交。
最佳答案
记住文件的 URL,然后在用户单击同意
时将其设置为 window.location
。
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
</head>
<body>
<a href="http://google.com" id="btn">Button</a>
<div id="dlg">Continue?</div>
</body>
</html>
JavaScript:
var dlg$ = $('#dlg').dialog({
title: 'Confirm action',
autoOpen: false,
buttons: {
'Agree': function() {
dlg$.dialog('close');
window.location = dlg$.data('url');
}
}
}),
btn$ = $('#btn').on('click', function(e) {
e.preventDefault();
dlg$.data('url', this.href).dialog('open');
});
关于javascript - 如果使用了preventDefault,如何继续下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12592469/