Ajax下载

时间:2022-01-12 06:47:11
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script> function setUnloadConfirm() {
window.onbeforeunload = function () {
return "您确定要离开吗?";
};
if (typeof window.disableTabClose === 'function') {
window.disableTabClose.call();
}
} function cancelUnloadConfirm() {
window.onbeforeunload = null;
if (typeof window.enableTabClose === 'function') {
window.enableTabClose.call();
}
} var download = function (url) {
cancelUnloadConfirm();
$('<form name="ajaxDownLoad" id="ajaxDownLoad" action="' + url + '" method="post">' +
'</form>')
.appendTo('body').remove();
setTimeout(setUnloadConfirm, 100);
}; var aaadownload = function () {
download(document.getElementById("txtUrl").value);
};
setUnloadConfirm();
</script>
</head>
<body>
<form action="http://localhost:8011/aaa.pdf" method="post">
<input type="button" value="下载" onclick="aaadownload();" />
<input type="submit" value="提交" />
<input id="txtUrl" type="text" value="http://localhost:8011/aaa.pdf" />
</form>
</body>
</html>