How to Open a PDF File in Javascript
Businesses can use PDF files as a way to distribute important corporate documents in a protected format. The business can password protect the files to restrict edits made to the file and even eliminate the printing option, making it impossible to send it to a printer. One language used to open these files is Javascript. Javascript is a common web programming language supported by several web browsers.
Instructions
-
-
1
Open your HTML file in your favorite editor. You can use a simple text editor or more advanced editors such as Notepad++ or Visual Studio.
-
2
Create a Javascript function that can be used in any area of your HTML file. The following code should be placed after the "<head>" tag in your file:
<script type="text/javascript">
function openPDF(file)
{
windows.open(file, 'resizable,scrollbars');
}
</script> -
-
3
Call the function from your PDF link on your web page. The following code is a link to a PDF file that calls the "open" function created above:
<a href="#" onClick="openPDF('myPDF.pdf')">Open the PDF File</a>
-
4
Save the file and open it with your web browser. Click the link to test the Javascript code. The link calls the open function and displays the PDF on your desktop.
-
1
References
- Photo Credit http, www, icon, web, website image by creative from Fotolia.com