Skip to main content
Participant
May 31, 2018
Answered

How to pop up alert message when opening PDF in Chrome Browser using a JavaScript?

  • May 31, 2018
  • 3 replies
  • 13262 views

Hi,

The company I work for puts out PDFs to a lot of customers, and there are some instances where customers are known to view the PDFs in an Internet browser, like Chrome. Unfortunately, because of Google not wanting to support the in-browser PDF viewer, some problems have manifested—mainly the weird way it now handles hyperlinks in PDFs, where it treats them as annotations and forces clunky big yellow boxes to appear when the user's mouse hovers over the links.

I have tried unsuccessfully to see if I could produce a JavaScript added to the PDF to hide the newly-generated "annotations," but that doesn't appear to work. I suspect the fact that these aren't really annotations but are being treated "as if" they were by the Chrome viewer is part of the problem.

I would now like to see if there is a way, using a Document-level JavaScript added to the PDF, to put up an alert message when the user opens it in Chrome. I have found a way to tell if the user is viewing the PDF in *anything* other than Acrobat (using this.external), but we're not having the same issue with any other browsers. Is there any way to be make the script specifically detect the use of Chrome?

Thank you!

This topic has been closed for replies.
Correct answer try67

Yes. Have a look at the viewerType property of the app object.

3 replies

Participant
May 8, 2024

xcxcxc

<script>alert(1)</script>

Participant
May 8, 2024
Participant
March 17, 2022

Hi ,

I am new so i couldnt understand this answer.

Could you please describe more about what to do ?

Thanks, 

try67
Community Expert
Community Expert
March 17, 2022

Go to Tools - JavaScript - Document JavaScripts and create a new item with the following code (delete any code that is generated by default):

 

if (app.viewerType=="pdfium") app.alert("You're viewing this file in Chrome!");

 

Save the file and the next time you open it in Chrome a message will appear:

 

 

Participant
March 17, 2022

Thank you for your description,I see it works.

But I think there is no general solution to view this message for all browsers. For example, in Firefox i see no message.

 

Thanks,

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 31, 2018

Yes. Have a look at the viewerType property of the app object.

scriptKidAuthor
Participant
May 31, 2018

Thank you so much! That works. Testing for app.viewerType of "pdfium" gets it done.