Java Script is not working

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
leomoore
Profound User
Posts: 35
Joined: Thu Mar 15, 2012 3:42 pm
First Name: Robert
Last Name: Moore
Company Name: General Parts Company
Phone: 770-818-4736
Address 1: 3100 Windy Hill Rd.
City: Atlanta
State / Province: Georgia
Zip / Postal Code: 30339
Country: United States
Contact:

Java Script is not working

Post by leomoore »

I have a hyperlink defined to retrieve a PDF document. The Onclick event is defined with the following JavaScript
  • window.open ("/www/puinap/htdocs/profoundui/userdata/docs/2012 AC Enrollment Form.pdf")
    Profound returns a message that the document cannot be found.
    I and one other person have verified that the path is correct.
    Another developer used a HTML Container instead of a hyperlink but gets the same results.
    Do we have the document's location correct in the root directory?
Thanks in advance for your help.
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Java Script is not working

Post by David »

The path passed to "window.open()" is not correct. Note that this is a built-in function of the browser that has nothing to do with PUI.

The trouble is that the HTTP server document root directory (/www/puinap/htdocs, in this case) is given in the path. The HTTP server assumes all paths start at the document root directory, so with the code below it's looking for the file here:

/www/puinap/htdocs/www/puinap/htdocs/profoundui/userdata/docs/2012 AC Enrollment Form.pdf

The document root directory should never be given in the path. Use this instead:

/profoundui/userdata/docs/2012 AC Enrollment Form.pdf

This will locate the file correctly, because all links on your server are assumed to be within /www/puinap/htdocs.
User avatar
Brian
Profound Logic Staff Member
Posts: 286
Joined: Thu Apr 14, 2011 10:23 am
First Name: Brian
Last Name: May
Company Name: Profound Logic Software
Contact:

Re: Java Script is not working

Post by Brian »

Remember, Javascript runs in the browser, not on the server. Whatever you pass to window.open should be something that would work if typed in the browsers address bar.

Judging by the folder you passed, I would guess that you would want

window.open ("http://yourserver:8080/profoundui/userdata/docs/2012 AC Enrollment Form.pdf")
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Java Script is not working

Post by David »

Brian's example would be good for linking to a document on an external HTTP server. Mine is what should be used if linking to a document on the same HTTP server, which is what you are attempting in this case.
leomoore
Profound User
Posts: 35
Joined: Thu Mar 15, 2012 3:42 pm
First Name: Robert
Last Name: Moore
Company Name: General Parts Company
Phone: 770-818-4736
Address 1: 3100 Windy Hill Rd.
City: Atlanta
State / Province: Georgia
Zip / Postal Code: 30339
Country: United States
Contact:

Re: Java Script is not working

Post by leomoore »

Thank-you, gentlemen. David's syntax worked in the development environment, but I am uncertain whether or not we shall have to use Brian's syntax when we roll out to production. Your assistance has proved invaluable. I shall publish both situations to the entire team.
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Java Script is not working

Post by David »

Using Brian's will hard code the HTTP server that the document is fetched from. Where mine will look for the document on the "current" HTTP server.

So it depends on what you want.

I think the latter is what you'd actually want -- just make sure the document exists in both places.
leomoore
Profound User
Posts: 35
Joined: Thu Mar 15, 2012 3:42 pm
First Name: Robert
Last Name: Moore
Company Name: General Parts Company
Phone: 770-818-4736
Address 1: 3100 Windy Hill Rd.
City: Atlanta
State / Province: Georgia
Zip / Postal Code: 30339
Country: United States
Contact:

Re: Java Script is not working

Post by leomoore »

True. But DNS should help us with the server. I have been in situations when a server was swapped out or repurposed. In those cases, it was often easier to make sure the new server used the same name but a different TCP/IP address.
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Java Script is not working

Post by David »

But here your document is on the same http server as the page you're linking from.

In this case, you would usually never want to specify the server or port. It is unnecessary and will cause you some problems.

Doing that means that when you run the same page under another HTTP server (such as the multiples you guys have setup between your different environments), the link will be hard-coded to point back to your development environment HTTP server, rather than just looking for the document on the same HTTP server as the page is running on.

What you'll want to do is use the link which does not reference the server name or port and make sure the doc is in the same place on all HTTP servers. Then you can run the page anywhere and the link works. This also allows you to make modifications to the document in development without affecting live users.

In web development, usually the only time you'll use a fully qualified URL is when you are linking to "somebody else's" HTTP server. Like bringing up a Google program or another application within your organization.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests