Web Connection
Opening PDF with one click
Gravatar is a globally recognized avatar based on your email address. Opening PDF with one click
  Harvey Mushman
  All
  Jan 29, 2017 @ 05:51pm

The one click PDF opening cleanly in all cases is always been an issue. After a bunch of additional reading and testing different ideas, I stumbled across the following:

<button ng-click="openPDF( params )> click me </button>
function openPDF( oParams ){
var pdfWindow = $window.open('about:blank','_blank');

// now I run my async request to WConnect asking for the dynamically generated PDF file.  The response returns a promise labeled below as data.url which is a link to the file.

pdfWindow.location = data.url;
}

And that is all there is to it! By opening a trusted webpage "about:blank" and then filling in the location, the popup blocker allows the PDF to be displayed in a new browser tab. So far all of my testing seems to work 100% of the time.

Any opinion, is this a valid solution or is there a more simple way to do the sae thing?

Gravatar is a globally recognized avatar based on your email address. re: Opening PDF with one click
  Rick Strahl
  Harvey Mushman
  Jan 29, 2017 @ 06:03pm

Yeah that's a good approach - of course you can provide the URL directly to the window.open() command so no need to actually have the extra controller action unless that's the desired behavior.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Opening PDF with one click
  Harvey Mushman
  Rick Strahl
  Jan 29, 2017 @ 09:06pm

Thanks for confirming, now I feel like I can release this version to my users....

As far as directly providing the url to $window.open(), it was causing the browser to consider the new URL as an untrusted site and caused a popup-blocking dialog to ask how I wanted to treat the page. This would confuse a lot of my users which I do not want to do.

What I learned is "about:blank" is always considered a trusted site for all browsers. Therefore, when creating the new window, I no longer worry about trusted vs untrusted and populate the location.url to my newly generated document.

thnaks again for your input.

Gravatar is a globally recognized avatar based on your email address. re: Opening PDF with one click
  Harvey Mushman
  Harvey Mushman
  Feb 3, 2017 @ 05:59am

After several days of testing on smartphones, I discovered an interesting setting on my old iPhone 3 (iOS 6). On this phone with Chrome browser, I could not get the new window to open until I changed the "Auto-Detect Encoding" setting found on the Content Settings sub menu. Now that I switched this feature on, this solution for opening PDF's without any problems.

On the other hand, in Apple Safari on this iPhone3, I have NOT been able to figure out how to make this work. I did reconfirm on iPhone 5 with Safari it just worked with no additional settings.

My Android Nexis 5 it just works. (Along with everything else... camera too!)

© 1996-2024