how to bypass popup's to download a pdf in new window

Naveen_Kumar
Level 2

how to bypass popup's to download a pdf in new window

Hi All,

My requirement is when i submit a form in landing page it should redirect to thank you page and once the thank you page loads the pdf should be downloaded in a new window or tab.

The pdf is opening in a new window but popup's are blocking is there any parameters we can put in window.open function?

I am writing the code in thank you page template to open a pdf in a new window but popup's are blocking

i have added setTimeout(window.open(".pdf", "_blank"), 2000) in document.ready function.

Below is the code :

$( document ).ready(function() {

  SocialManager.init();

      event.preventDefault();

      setTimeout(window.open(".pdf", "_blank"), 2000);

});

Thanks in advance !!

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: how to bypass popup's to download a pdf in new window

Answered several times, search the Community for "new window form."

Naveen_Kumar
Level 2

Re: how to bypass popup's to download a pdf in new window

Hi Sanford,

Thanks for the response. i had already searched in the community i see the answers related only after submitting the form but my requirement is that after loading a thank you page we set a timeframe like 2 to 5 sec and then the pdf should download in a new window.

I have to put the logic in the thank you page $( document ).ready(function() {

below is the code

$( document ).ready(function() {

  SocialManager.init();

      event.preventDefault();

      setTimeout(window.open(".pdf", "_blank"), 2000);

});

logic is correct only the issue popup's are blocking for that is there any parameter we can mention in the window.open function

Thanks.

SanfordWhiteman
Level 10 - Community Moderator

Re: how to bypass popup's to download a pdf in new window

The logic isn't actually correct, because

     [a] running preventDefault() on DOMContentLoaded isn't a thing (what default action would you be preventing?) and

     [b] there's no variable event in scope in your example (the global window.event is not present in all browsers)

But the main problem is, as described on those other threads, you can only run window.open() in response to deliberate user interaction, i.e. it has to be part of continuous event handling after a mouse click.

Loading a new page doesn't meet the security criteria for user-driven events; even if the new page navigation originated from a deliberate user-driven event, by the time the new page loads that context is lost. I recommend you load the follow-up content in the same page as the form, so the event handling can continue as usual.