HTML Href how to open a file as text - html

Is there a way to use
test
but when clicked it opens the html file as a text file, like what happens when you open a css file in your browser

You need to use the file:/// protocol if you want to link to local files. So in your case paste file path with that three slashes.
Code Example:
test.html
test.css
I hope this will help you out if not, do let me know!

Related

Can you download a file from homepage using localhost?

I have this a tag <a href="/assets/test.docx" download>Download</a>. According to W3schools it seems like I have setup right path to access file test.docx form CV.vue according to folder structure in the picture below. Please check and verify that I have right path.
I want to test download the file when running website in Chrome on localhost. When I click download I get error saying Failed, no file
What am I doing wrong?
Folder structure
Generally if you put slash(/) behind of your path in href, it will going to main domain of website and it doesn't matter it's localhost or real domain like example.com.
So if you find your path or file structure easily you can put that in href parameter.
For example your logo path is:
src/assets/logo.png
*Remember that you can test it by enter you path on your browser to find your correct path.
for example:
localhost/src/assets/logo.png
OR
127.0.0.1:8000/src/assets/logo.png
If it's working correctly, you can put that on your html code like this:
Download
The answer is simple just remove the forward slash in front of "assets". Your code should be:
<a href="assets/test.docx" download>Download</a>
The html download attribute will add this extra slash so your code as it exists now leads to the following path.
file:///assets/0513211459.jpg.html

using TextEdit on Mac...doesn't display as a web page. advice?

I save a basic "Hello World" html file on TextEdit on my mac, but it won't open as a webpage and I just see code when I open the file.
Go to your text edit and under prefrences
Make sure this is checked
Make sure plain text is selected
Create a new file and named the file with format also
For example: index.html <--- where html is the format
Then you are good to go!

How to write html file with a text editor

I am trying to write my first html document.
Here is the link to the reference.
I am using TextEdit on Max OSX 10.6 and after I save it (as an html file) it is opened by the browser by double clicking on it. However the source script text is shown instead of the html structure.
What I am getting wrong?
You need to convert it to a plaintext document
Click Format and then 'Make Plain Text', then make sure to save as .html
Does the icon of the file has an "e". Usually these kind of files should have an icon as an e. Also make sure you are saving it as .html file. I think the actual extension of the file is hidden.

HTML web download link for text file

I'm using HTML web and i want, that users could download a file like .vbs (skype bot) and then i use code like this:
<a href='skypebot.vbs' target='_blank'>download</a>
I get just only that file text. How can i make it download link not uploading it to other site like zippyshare?
How can i make it download link not uploading it to other site like
zippyshare?
You can use a data link. Put the contents of your file (encoded with encodeURI() ) in the link itself:
<a href='data:application/octet-stream,encodeURI(hereContentsGoes)' target='_blank'>download</a>
The file is probably being recognized as a vbs type by your browser, and trying to display it.
Easiest solution is to zip or tar the file and have that be the downloadable file.
<a href='skypebot.zip' target='_blank'>download</a>

Link to open PDF from folder

I have some PDF's sitting in a folder on my computer, is there a way to write a link to open them on to a webpage?
The main idea is when the site goes live the link will be used to download the pdfs from the folder, but obviously at a later stage the folder will be a temp folder on my website.
So at the moment i just want to open the pdfs from a link, and the final goal will be to have the links download them.
Can any one help me?
This is the file path to get to the pdf i want to link to.
C:\Users\Shaun\Documents\FormValue\CS1.pdf
How would i create the link?
If you want to have a link to a PDF, you just have to put the relative path to the file in the href attribute of an a tag. So let's say you had a folder called pdfs, with the file boom.pdf inside it, and folder called site sitting beside it, with the file site.html in it. Then all you'd have to do is put this link in the html file:
Link to a pdf
In most (all?) browsers now a days, that will open the PDF in a new tab. To download it you would right-click it and do the Save Link As thing. Just need to get the path in href right.
UPDATE
If you want to use the full path to the file, you need to prefix it with file://. Then you just put it in the href the same as with a regular link, ending up with something like:
Link to a pdf
This should work with your set up, but if the pdf and the html files are stored near each other, relative URLs are still a good option. A little bit of Google work should show you how to write those.
For each PDF just do what I talk about here.
<object height="950" data="sample-report.pdf" type="application/pdf" width="860">
<p>It appears you don't have a PDF plugin for this browser.
No biggie... you can <a href="sample-report.pdf">click here to
download the PDF file.</a>
</p>
</object>
It works with most browsers and it degrades nicely.
It sounds like youre asking if you can put a link on a web site to a PDF sitting on your computer. You can't. The files have to be either on another web site or on your site's server.
If you are using ASP.NET, you can have the link point to a handler that accepts a query string identifying the file, either by file name or a hash of the file. Then the handler can look in the folder for a file that matches the pattern, read the file as a byte array, and then write those bytes to HttpResponse.