$('#downloadBtn').click(function() { window.location.href = 'path/to/your/file.pdf'; // }); Use code with caution.
For a more seamless experience without refreshing the page, you can dynamically create a hidden link: javascript download file jquery
const link = document.createElement('a'); link.href = 'file-url.zip'; link.download = 'custom-name.zip'; document.body.appendChild(link); link.click(); link.remove(); // Use code with caution. 2. Downloading Files via AJAX (POST/GET) $('#downloadBtn')
The most straightforward way to download a file is to use an anchor ( ) tag. You can use jQuery to dynamically set the file path or trigger the click event. link.href = 'file-url.zip'