Open pdf in new tab with jQuery

971 Views Asked by At

I've the following code working properly which opens a pdf downoloaded in the same window:

jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
    .appendTo('body').submit().remove();

I'd like open the pdf in a new tab or window.. How can I change the appendTo in order to achieve it?

Thanks in advance!!

3

There are 3 best solutions below

0
Arun P Johny On BEST ANSWER

You can set target="_blank"

jQuery('<form target="_blank" action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>')
  .appendTo('body').submit().remove();
0
7urkm3n On

Add target='_blank' attribute into forms.

target="_blank"
0
Yasin On

I think you can use $.ajax or $.post to get pdf url and you can use window.open() to open this url in new tab:)