<html>
<head>
<script src=”jquery-1.8.3.min.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(“.lnkDownFile”).click(function() {
//点击下载时,将GIF图片追加到下载A标签后面
$(“<img class=”waitImg” src=”wait.gif”></img>”).insertAfter(this);
//文件下载地址
var targetAPI=”http://192.168.3.107:82/logic/FileHandler.ashx?method=DownLoadAttach&attachIdentity=967b6af3-ab16-4001-82c1-40831466a66b”;
CreateIFrame(“downFrame”, targetAPI);
});
});
//创建iframe
function CreateIFrame(frameID, targetURL) {
var downFrame = document.getElementById(frameID);
if (downFrame == null) {
downFrame = document.createElement(“iframe”);
downFrame.id = frameID;
downFrame.name = frameID;
downFrame.style.display = “none”;
}
downFrame.src = targetURL;
// 下载完后删除GIF图片
// downFrame.onreadystatechange = function() {
// if (downFrame.readyState == “complete” || downFrame.readyState == “interactive”) {
// $(“img”).remove(“.waitImg”);
// }
// };
document.body.appendChild(downFrame);
}
</script>
</head>
<body>
<a class=”lnkDownFile” href=”javascript:void(0);”>下载</a>
<iframe id=”downFrame” name=”downFrame” style=”display:none;” ></iframe>
</body>
</html>
20
20
<html> <head> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $(".lnkDownFile").click(function() { //点击下载时,将GIF图片追加到下载A标签后面 $("<img class="waitImg" src="http://www.dabaoku.com/gif/153/gif002.gif"></img>").insertAfter(this); //文件下载地址 var targetAPI="http://www.dabaoku.com/gif/036/gif127.GIF"; CreateIFrame("downFrame", targetAPI); }); }); //创建iframe function CreateIFrame(frameID, targetURL) { var downFrame = document.getElementById(frameID); if (downFrame == null) { downFrame = document.createElement("iframe"); downFrame.id = frameID; downFrame.name = frameID; downFrame.style.display = "none"; document.body.appendChild(downFrame); } downFrame.src = targetURL; downFrame.style.display = ""; // 下载完后删除GIF图片 // downFrame.onreadystatechange = function() { // if (downFrame.readyState == "complete" || downFrame.readyState == "interactive") { // $("img").remove(".waitImg"); // } // }; } </script> </head> <body> <a class="lnkDownFile" href="javascript:void(0);">下载</a> <iframe id="downFrame" name="downFrame" style="display:none;" ></iframe> </body> </html>