These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Open a web link based on URL of PDF

Mollies Mom
Registered: Feb 10 2010
Posts: 8

We have an Acrobat 9 form that gets posted to 3 different web sites.

I want to create a button that will execute a java script to open a web link based on the URL of the PDF. This way, one PDF can be loaded on all 3 web sites, but can execute different web links based on where it is located.

1. Determine url address and capture it to a hidden field (at a Document level script?)

2. Create button based on value of #1 hidden field:
if web address = a --> go to link 1
if web address = b --> go to link 2
if web address = c --> go to link 3

Can someone point me in the right direction?

My Product Information:
Acrobat Pro 9.3.1, Windows
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
if(app.doc.path == "http://www.someplace.com/somewhere.pdf")getURL("url1");else if(app.doc.path == "http://www.someplace2.com/somewhere.pdf")getURL("url2");etc...

I would probably also only compare the string up to the .pdf in case you use a querystring or in case they do somehow.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

Mollies Mom
Registered: Feb 10 2010
Posts: 8
Hey, thanks so much. I tried your suggestion at home and then we tried it on a real application at work and it seems to be working okay. I included the entire path of the document to make a match including the .pdf. Was wondering if you could explain more about your comment to compare only up to the .pdf in case of a querystring... At home it didn't seem to work if I left off the .pdf or file name.
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
I meant to only compare the start of the app.doc.path to the url you have in case the path just starts with the url and has more after the URL like a querystring or startup parameters. For example, your app.doc.path might be:
http://www.someplace.com/somewhere.pdf#page=2

and then the strings would not match, but you would want to treat them as if they do match, so you should do (and now that I think about it, more importantly, you should also make the strings lowercase for the compare):
if(app.doc.path.substring(0, "http://www.someplace.com/somewhere.pdf".length).toLowerCase() == "http://www.someplace.com/somewhere.pdf")
getURL("url1");

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

Mollies Mom
Registered: Feb 10 2010
Posts: 8
One more question for you... Can I add a "true" parameter to the end to get the URL to launch in a new window?

E.g.:
getURL("http://www.whatever.com/thispage.htm", true);