Using td onclick= to view local pdf file

Posted on 2007-10-15
Last Modified: 2008-01-09
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)

Question by:scbdpm
    LVL 23

    Expert Comment

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

    start with this:

    <td onclick="'pathToPdf.pdf');">

    Author Comment

    I would like to open the PDF in a webbrowser control/window in VB....
    LVL 4

    Accepted Solution

    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.
    LVL 54

    Assisted Solution

    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.

    LVL 54

    Expert Comment

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


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now