Download File Using JavaScript jQuery

0 votes

I have a very similar requirement specified here.

I need to have the user's browser start a download manually when $('a#someID').click();

But I cannot use the window.href method, since it replaces the current page contents with the file you're trying to download.

Instead I want to open the download in new window/tab. How is this possible?

Jun 3, 2022 in JQuery by Edureka
• 13,670 points
2,713 views

1 answer to this question.

0 votes

Suppose you want to download a file when you click on a link. For downloading the file, we mentioned here to implementation as well as folder structure where you can see the file location.

Approach:

  • Create an anchor tag link on the normal HTML page.
    <!DOCTYPE html>
    
    <html>
    
    
    
    <head>
    
    <title>
    
    Download File Using
    
    JavaScript/jQuery
    
    </title>
    
    </head>
    
    
    
    <body>
    
    <h1>
    
    Download File Using
    
    JavaScript/jQuery
    
    </h1>
    
    
    
    <a id="link" href="#">
    
    Download this file
    
    </a>
    
    </body>
    
    
    
    </html>
answered Jun 3, 2022 by Edureka
• 13,670 points

Related Questions In JQuery

0 votes
1 answer

Download File Using JavaScript/jQuery

Download Files Create a DOMString that contains the ...READ MORE

answered Jun 10, 2022 in JQuery by gaurav
• 23,260 points
1,519 views
0 votes
1 answer

Download File Using JavaScript/jQuery

<!DOCTYPE html> <html> <head> <title> Download File Using JavaScript/jQuery </title> </head> <body> <h1> Download File Using JavaScript/jQuery </h1> <a id="link" ...READ MORE

answered Jun 10, 2022 in JQuery by rajatha
• 7,640 points
918 views
0 votes
1 answer

Download pdf file using jquery ajax

Download PDF file with button click using ...READ MORE

answered May 30, 2022 in JQuery by gaurav
• 23,260 points
19,033 views
0 votes
1 answer

How do I check if file exists in jQuery or pure JavaScript?

Hello @kartik, With jQuery: $.ajax({ url:'http://www.example.com/somefile.ext', ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,880 points
5,957 views
0 votes
1 answer

Download a file by jQuery.Ajax

Downloading files using AJAX method $("#FileDownloadBtn"). click(function () ...READ MORE

answered Jun 10, 2022 in JQuery by gaurav
• 23,260 points
2,673 views
0 votes
1 answer

How to import jQuery UI using ES6/ES7 syntax?

Hii, Add a alias in webpack config: resolve: { ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
7,425 views
0 votes
1 answer

How can I implement my own $(document).ready functionality without using jQuery?

Hello @kartik,  There are three options: If script is the last ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
1,340 views
0 votes
1 answer

How to convert form data to JavaScript object with jQuery?

Hello @kartik, You can use: function form_to_json (selector) { ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
2,690 views
0 votes
1 answer

How to change color of SVG image using CSS (jQuery SVG image replacement)?

Edit your SVG file, add fill="currentColor" to ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,670 points
21,484 views
0 votes
1 answer

How to add class using jQuery?

Add a class name to the first ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,670 points
2,646 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP