Ajax下载

<!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>

 

posted @ 2018-06-08 09:34  昨日微风  阅读(144)  评论(0编辑  收藏  举报