Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <a href="http://website.com/example_1.txt" download="saved_as_filename.txt" id="downloader">
- static download link</a>
- var theURL = 'http://foo.com/example_2.txt';
- $('#downloader').click(function() {
- $(this).attr('href',theURL);
- });
- $('#downloader').css('display','none');
- function initiateDownload(someURL) {
- theURL = someURL;
- var event = document.createEvent("MouseEvent");
- event.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
- // dispatch event won't work on a jQuery object, so use getElementById
- var el = document.getElementById('downloader');
- el.dispatchEvent(event);
- }
- initiateDownload('example_3.txt');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement