Automatically download PDF after form submit
-
Good day to all!
Help me solve the problem.
I need the presentation PDF file to start downloading automatically to the client’s computer after sending the form, or a new window to open with the downloaded file.With a standard redirect, the file opens in the same window and exits the page, thus creating the possibility of losing the client.
The chatGPT gave such a solution, but it does not work.
<script>
document.addEventListener('DOMContentLoaded', function() {
var formElements = document.querySelectorAll('.metform-form-content');
formElements.forEach(function(formElement) {
document.addEventListener('metform_after_submit', function(event) {
setTimeout(function() {
var fileUrl = 'https://yourwebsite.com/uploads/yourfile.pdf';
var link = document.createElement('a');
link.href = fileUrl;
link.setAttribute('download', '');
document.body.appendChild(link);
link.click();я
document.body.removeChild(link)
}, 1000);
});
});
});
</script>Thank you
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.