Last active
June 5, 2016 11:19
-
-
Save black-black-cat/946cdb4d1ca470f0e61a1aa62c67c277 to your computer and use it in GitHub Desktop.
利用iframe实现下载时不跳转
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {String} downloadUri | |
| * @param {Boolean} useIFrame | |
| */ | |
| function startDownloading(downloadUri, useIFrame) { | |
| if (!downloadUri || !downloadUri.length) { | |
| return; | |
| } | |
| if (useIFrame === void 0) { | |
| useIFrame = true; | |
| } | |
| if (!useIFrame) { | |
| window.location.href = downloadUri; | |
| } else { | |
| var frame = $("<iframe />"); | |
| frame.appendTo($("body")).attr({ "src": downloadUri, "display": "none" }); | |
| setTimeout(function () { | |
| frame.remove(); | |
| }, 600000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment