0

I am trying to use my html\ javascript to access a PDF file.

I have checked to see if the file exists which it dose however its still returning an error alert stating that the file is not found could someone elaborate on this form me?

<p>Zoek voor project Nr: 
<input type="text" name="prog_site" id="prog_site" value="" />
<a href="#"
   onclick="this.href = ('file://j:/' + document.getElementById('prog_site').value + '/Tekeningen/TekenwerkDeMar/Definietief/' + document.getElementById('prog_site').value + '.pdf' )"
   target="_blank">Get</a>

2
  • If it returns an error, something are wrong on that. :) Is that a web site or localhosted? Commented Nov 19, 2013 at 9:35
  • You can't access local files from the web for obvious security reasons. Commented Nov 19, 2013 at 9:37

3 Answers 3

1

You need use domain path instead of file path

this.href = ('http://example.com/' + document.getElementById('prog_site').value + '/Tekeningen/TekenwerkDeMar/Definietief/' + document.getElementById('prog_site').value + '.pdf');

or even instead for in local instance use localhost or ipadress with port if configured.

Sign up to request clarification or add additional context in comments.

Comments

1

Most browsers have restrictions on opening local files from a website. If this were allowed, anybody could read your personal files from any website you are visiting.

A) You can upload the file to some webhost to access it via the http: instead of file: schema.

or

B) You can let the user select the file via <input type="file" /> and access it via the DOM File API.

Comments

0

try something like this

CHANGE THIS

   file://j:/

TO

   http://localhost // server [use your server url]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.