Page 1 of 1

Java Script is not working

Posted: Thu Apr 12, 2012 12:40 pm
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.

Re: Java Script is not working

Posted: Thu Apr 12, 2012 1:08 pm
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.

Re: Java Script is not working

Posted: Thu Apr 12, 2012 1:11 pm
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")

Re: Java Script is not working

Posted: Thu Apr 12, 2012 1:15 pm
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.

Re: Java Script is not working

Posted: Thu Apr 12, 2012 1:41 pm
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.

Re: Java Script is not working

Posted: Thu Apr 12, 2012 2:17 pm
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.

Re: Java Script is not working

Posted: Thu Apr 12, 2012 3:17 pm
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.

Re: Java Script is not working

Posted: Thu Apr 12, 2012 4:48 pm
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.