Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-browser link to file on local system

Tags:

I would like to make a link from a web page to a file on a local filesystem and make it work in all browsers (or at least in Internet Explorer, Firefox and Chrome).

For example, the following works in Internet Explorer:

<a href="\\myserver\doc\info.pdf">Info here</a>

but not in Firefox and Chrome.

Is there a way to make a link that works in all browsers?

Or a way to use javascript to detect which browser it is and then display the appropriate link based on the filename?

like image 534
Ole Lynge Avatar asked Aug 10 '09 12:08

Ole Lynge


People also ask

Can a browser access local files?

Web browsers (and JavaScript) can only access local files with user permission. To standardize the file access from the browser, the W3C published the HTML5 File API in 2014. It defines how to access and upload local files with file objects in web applications.

How do I make a link directly to a file?

Create a hyperlink to a file on your computerSelect the text or picture that you want to display as a hyperlink. Press Ctrl+K. Under Link to, do one of the following: To link to an existing file, click Existing File or Web Page under Link to, and then find the file in the Look in list or the Current Folder list.

How do I link a file in HTML from my computer?

The <a href=" filename"> tag signifies a link is coming and the file name is the target of the link (where you will jump to). The text between the <a href=" filename"> tag and the closing tag </a> is the second piece of the link. This text will be highlighted in your document.


2 Answers

Links to local files on pages that were retrieved via HTTP(S) are deliberately disabled in Mozilla/Firefox, because they can be a security risk, and have been used in attacks in the past.

You can override this behaviour, however. For details, see this article in MozillaZine.

like image 147
sleske Avatar answered Sep 22 '22 11:09

sleske


try prefixing your url with file:///

like image 27
smercer Avatar answered Sep 20 '22 11:09

smercer