• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaScript to perform Google search

Explorer ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Hi Everyone,

 

I have a field that asks the user for a full address to be typed in. I'd like to add a button that, when clicked, launches the default browser and performs a Google Maps search of that address. Or, at the very least, a Google search of that address. 

 

Is there a relatively easy script that can be applied to that button? 

bhull_0-1586884278815.png

 

TOPICS
Acrobat SDK and JavaScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 14, 2020 Apr 14, 2020

Like this:

app.launchURL("https://www.google.com/maps/search/" + this.getField("Full Address").valueAsString);

 

Just to clarify: This will open the URL in the default browser. It will NOT make the results accessible to your code or allow you to embed them in your PDF or anything like that.

Votes

Translate

Translate
Community Expert ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

The short answer is NO. Acrobat form scripts have no mechanism for receiving and interpreting results from a web API.

 

But, there are a couple of other options. If you could install an Acrobat automation script on to the user's system, then that script could execute SOAP and regular HTTP request.  If this is not possible, then the other option is to write a server script that does the api calls to google maps. This scirpt would get the form submit from the PDF, interact with google, and return results that the PDF form can use.  

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Thanks Thom. Very helpful. What about this as a workaround: using JavaScript to open a browser tab that includes the content provided in that field appended to a URL? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

You can do it, actually, by using this URL:

https://www.google.com/maps/search/YourSearchQuery

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Thanks for the note. How would I append the parameter that the user types in to that field to the "YourSearchQuery" however? I know I can't hardcode it using the Action of opening a web link, so I'm assuming I have to use JavaScript. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Like this:

app.launchURL("https://www.google.com/maps/search/" + this.getField("Full Address").valueAsString);

 

Just to clarify: This will open the URL in the default browser. It will NOT make the results accessible to your code or allow you to embed them in your PDF or anything like that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

LATEST

Brilliant. Thank you so much. Worked like a charm. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines