Download File Using URL On Same Page From Jquery/Javascript

Category: JAVA SCRIPTJQUERY Comments: One comment

Download File Using URL On Same Page From Jquery/Javascript :-

var data = FileUrl;

function downloadpdf(data) {

jQuery(“a.print-page-pdf”).attr(“href”, data);

jQuery(“a.print-page-pdf”).attr(“target”, “_blank”);

 

var Chrome,

Safari,

Firefox,

IE;

if (navigator.userAgent.indexOf(“Chrome”) != -1)

Chrome = true;

else if (navigator.userAgent.indexOf(“Safari”) != -1)

Safari = true;

else if (navigator.userAgent.indexOf(“Firefox”) != -1)

Firefox = true;

else if ((navigator.userAgent.indexOf(“MSIE”) != -1) || (!!document.documentMode == true)) //IF IE > 10

IE = true;

 

if (Chrome || Safari) {

//Creating new link node.

var link = document.createElement(‘a’);

link.href = data;

 

if (link.download !== undefined) {

//Set HTML5 download attribute. This will prevent file from opening if supported.

var fileName = data.substring(data.lastIndexOf(‘/’) + 1, data.length);

link.download = fileName;

}

 

//Dispatching click event.

if (document.createEvent) {

var e = document.createEvent(‘MouseEvents’);

e.initEvent(‘click’, true, true);

link.dispatchEvent(e);

return true;

}

}

 

// Force file download (whether supported by server).

var query = ‘?download’;

window.open(data + query);

}

Tags:  

One comment on “Download File Using URL On Same Page From Jquery/Javascript

  1. Looking for an application like truecaller to trace mobile number using c# dotnet

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.