How to download a pdf link?
suppose we have a pdf url (like "http://images.apple.com/support/itunes_u/docs/iTunes_U_User_Guide.pdf") now i have to create a button on click of which it downloads that pdf.
i have tried window.open() method in javascript but it opens it in another window.
is there a way to download a pdf link using javascript or ajax.
a java code also is appreciated

Recommended Answers

All 3 Replies

download a pdf link

This will open a .pdf in the same window (unless your browser or viewer is configured not to do so).

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
    <title></title>
  </head>
  <body>
<button onClick="window.location='http://---whatever---.pdf'">Open .pdf!</button>
  </body>
</html>

i do not want to open it in the same window( or another window), i want that if user clicks the button it gets an option to save the pdf file.

That function is available only in IE, and even there it is commonly disabled for security reasons. Just make a regular link and let those who wish to take the risk use right-click to save the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.