0

I have a program (Mendeley) that tries to open PDF files that are stored locally by accessing the URL: http://path.to/file.pdf (instead of file://path.to/file.pdf). This results in an error in my browser (not unexpected).

What I would like to do is have a javascript bookmarklet that uses the URL in the address bar (which is basically correct besides the http part) and opens the file in an external viewer (Acrobat in my case). My latest creation (inspired by other examples on SO has been):

javascript:var a = (location.pathname); 
var b = ('file://schbs02'+a);  
window.location =  (b);`

This does NOT work; in Chrome (latest version) nothing happens. Is it an inherent limitation of bookmarklets (for security purposes) that they can not open local files or is there something wrong with the code?

craig_h
  • 31,871
  • 6
  • 59
  • 68
  • To test, simplify your code to something like: `javascript:alert('test');document.location='file://yourpath/yourfile.pdf';`. If the alert fires, but the file doesn't open, then it seems to be a security limitation. Also, as a side note, you didn't need any of the parenthesis in your example code. – DG. May 08 '12 at 07:40
  • Thanks for your tip. Playing around revealed more strangeness: IF the tab/page currently open already accesses/shows/exposes the local file system, your bookmarklet works, if it accesses an http site it does not (i.e. I only get the alert but no page open)... I'll have to play around some more with bookmarks exposing the local file system or some such thing... Maybe I can get a combination of bookmarks and bookmarklets to work. – user1381385 May 08 '12 at 09:18
  • Which brings me to my next question: is it possible to open (previously saved) bookmarks using a bookmarklet? I assume not (security again)... – user1381385 May 08 '12 at 09:31

0 Answers0