HTML: Force opening a local file
Anonyme209
Posted messages
761
Status
Member
-
Anonyme209 Posted messages 761 Status Member -
Anonyme209 Posted messages 761 Status Member -
Hello,
I am creating an HTML page containing links to local files on my computer (files of different formats).
When I click on a link, if the target file cannot be OPENED in the browser (executable files, Word, Excel, etc.), my browser opens a window and offers to "download" the file. However, I want my browser to directly open the file with the associated program.
I specify that I cannot use PHP...
Thank you for your help.
I am creating an HTML page containing links to local files on my computer (files of different formats).
When I click on a link, if the target file cannot be OPENED in the browser (executable files, Word, Excel, etc.), my browser opens a window and offers to "download" the file. However, I want my browser to directly open the file with the associated program.
I specify that I cannot use PHP...
Thank you for your help.
1 answer
Hello,
well, that's the normal functioning of a browser.
The opposite is deliberately (and logically) prohibited, as the web and http are not - fortunately - the property of Microsoft.
An executable file is made to run locally and especially cannot execute from a web browser (thankfully, just think about it: .exe launching by visiting a web page = computer hacked and open to everything just by viewing a page), which, as its name indicates, is designed to display web pages and their content.
However, since HTML5, you have the download attribute:
http://www.w3schools.com/tags/att_a_download.asp
which allows you to indicate it as downloadable content and thus prevent the browser from looking for a way to open the file and refine the indexing.
For office files (LibreOffice is far better than Microsoft Office and free, gradually replacing the commercial solution in administrations + companies), you have extensions that can read these files.
This is not ideal, and the display of the files is not guaranteed to be respectful; it forces users to have the extension and know how to use it.
I don't know why you are talking about PHP; there may possibly be encoding libraries for office files.
I don't know what your goal is, but using office solutions made for secretarial work and local administration on a wide (global) network is inconsistent.
Office work is, as its name indicates, for doing office work; for publishing on the web, you cannot (nor should) use such tools.
Use appropriate tools, like a database feeding your site and generating pdf documents if they need to be downloaded.
You will need to go through PHP or an equivalent, possibly a CMS that will generate them - it all depends on the specific needs of your site/program. We are talking about information systems:
https://www.commentcamarche.net/contents/1083-systeme-d-information
It's not just the way things should be done but also the means to automate, i.e., doing once and for all the layout for all spreadsheet sheets or word processing pages (of the same document type, of course) with HTML and CSS will allow you to reuse that layout endlessly through what are called dynamic pages. Your solution is not one because it will force everyone to create a text or spreadsheet file in order to convert it (to a web page or better, a database) and disseminate it.
Simplify your life; sometimes that means learning efficient and suitable tools.
Office work is for office tasks; for the web, you must use the technologies (most free and open) associated with it (simpler and standardized than those of office work, which, as its name indicates, is made for office tasks).
well, that's the normal functioning of a browser.
The opposite is deliberately (and logically) prohibited, as the web and http are not - fortunately - the property of Microsoft.
An executable file is made to run locally and especially cannot execute from a web browser (thankfully, just think about it: .exe launching by visiting a web page = computer hacked and open to everything just by viewing a page), which, as its name indicates, is designed to display web pages and their content.
However, since HTML5, you have the download attribute:
http://www.w3schools.com/tags/att_a_download.asp
which allows you to indicate it as downloadable content and thus prevent the browser from looking for a way to open the file and refine the indexing.
For office files (LibreOffice is far better than Microsoft Office and free, gradually replacing the commercial solution in administrations + companies), you have extensions that can read these files.
This is not ideal, and the display of the files is not guaranteed to be respectful; it forces users to have the extension and know how to use it.
I don't know why you are talking about PHP; there may possibly be encoding libraries for office files.
I don't know what your goal is, but using office solutions made for secretarial work and local administration on a wide (global) network is inconsistent.
Office work is, as its name indicates, for doing office work; for publishing on the web, you cannot (nor should) use such tools.
Use appropriate tools, like a database feeding your site and generating pdf documents if they need to be downloaded.
You will need to go through PHP or an equivalent, possibly a CMS that will generate them - it all depends on the specific needs of your site/program. We are talking about information systems:
https://www.commentcamarche.net/contents/1083-systeme-d-information
It's not just the way things should be done but also the means to automate, i.e., doing once and for all the layout for all spreadsheet sheets or word processing pages (of the same document type, of course) with HTML and CSS will allow you to reuse that layout endlessly through what are called dynamic pages. Your solution is not one because it will force everyone to create a text or spreadsheet file in order to convert it (to a web page or better, a database) and disseminate it.
Simplify your life; sometimes that means learning efficient and suitable tools.
Office work is for office tasks; for the web, you must use the technologies (most free and open) associated with it (simpler and standardized than those of office work, which, as its name indicates, is made for office tasks).
With the texts and values from the spreadsheet stored in a database, you will be much more efficient than with Word or Excel (by far) and updated instantly for the audience(s) that the publication is intended for. If you are still adamant about using such files, the simplest way is to convert them into .txt (thus without Word formatting) and for spreadsheets into so-called separator formats (like CSV) in order to use their content in your pages.
I believe we haven't understood each other very well.
On an HTML page, I list documents located on my computer that are not accessible online.
Then, I open this page locally with my browser.
I want that when I click on a document link, it opens directly (or asks me if I want to open it) instead of offering to download it.
I mentioned executable files, Word, and Excel as examples, but it could be any other type.
The download attribute is not useful to me; that's precisely what I want to avoid.
Thank you for your help.
But the reasoning remains the same, opening a file without the user explicitly requesting it (a click isn't, that's the way of the web for us developers, not the other way around) doesn't leave any choice.
For that, there are the browser preferences (either default or modified by the user if they want this behavior) and it would represent a risk.
The device the user is using also comes into play:
What would happen if this were possible? The user would already need a program capable of reading the file, and that program (the one the user wants) would need to be the default program for the type of files concerned.
This presents more risks of errors and problems than anything else:
You suggest opening a Word file for someone who doesn't have any word processing software installed, or is using a mobile device...
You propose an .exe file while the user is on a Mac, Linux, their mobile, or their tablet, not to mention the security risks of opening a file directly, whether it's an .exe or otherwise, as it could very well contain malicious software!
I'm not even mentioning the security reasons (opening an infected file directly = not good).
For other information, consider my opinion and the more advantageous and simpler option of presenting your documents directly; otherwise, you'll have an information system that doesn't hold up and will be cumbersome (just compare the size of a file with that of a text record of the same content for text contents, in text for a link to another resource).
Since you mention image files, if the goal is to display them, it's best to do it on the webpage rather than making users download them (that's what the browser is supposed to do).
Forcing an operating system to open a file is thankfully impossible.
I hope to guide you towards a better way of doing things.
I don't know your need, but in an effort to improve usability with a click, you're going against normal and healthy practices, which are also mandatory.
So reconsider your approach if you want to improve your site, as this path leads nowhere and seems disadvantaged compared to a normal rendering solution on the page (and a clean and sustainable content management system, which your method is not).