• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2941
  • Last Modified:

Using td onclick= to view local pdf file

I am new to JavaScript so bear with me....

How can I use "td onclick=" to open a local file (am specifically looking to open/view a pdf in my webbroswer)

2 Solutions
it really depends what you are trying to do...

start with this:

<td onclick="window.open('pathToPdf.pdf');">
scbdpmAuthor Commented:
I would like to open the PDF in a webbrowser control/window in VB....
Open PDF that is local to web server or your computer? Or are you trying to package the webpage and PDF into a CD that launches web browser, etc.?

If not running from CD or web server, I fail to see why you want to open a PDF in web browser. If you want to do so on local computer as some type of application, you might want to make the HTML webpage into a Microsoft HTA application, which is a client side HTML webpage that allows you to use VBScript and javascript and provides extra features that are blocked from standard HTML due to security restrictions.

And it is usually better to attach an onclick to an image, button, or link, not a table cell. If you want to load a PDF into web browser from a webpage, you could use frames or launch a new web browser window and have the link target attribute set to the name of the frame or new window. <a href="..." target="_blank"> will automatically load the link in a new window. And if the web browser has PDF plugin installed correctly, if you just have simple link like <a href="my.pdf">, it will load the PDF in the same browser window replacing your current page.
If the file is on the computer with the browser then you can't.  Browser security should stop this.  There are exceptions (e.g. the page is local, on an intranet, or a few, bad browsers) but in general the browser won't let javascript (or any script) access the computer.  The example the expert provided above would try to open pathToPdf.pdf in the same folder as the webpage file.

Let me know if you have a question or need more info.

I'm glad I could help.  Thanks for the grade, the points and the fun question.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now