Can you download a file from homepage using localhost? - html

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

Related

How do I change the path of a site in HTML, CSS, or JS?

How can I change the path of my site using HTML, CSS, or JS. I may be using the wrong grammar here using the word "path", but what I'm referring to is a subdomain, an example would be stackoverflow.com --> stackoverflow.com/questions
I attempted to use the element
<a href="about.html">
<img src="x">
</a>
but it did not work,
You could think of a server's public folder (the one that host your site's static files as HTML, CSS, Js) as a directory in your computer. For you to redirect the user to another path in your site you can use as you said Your link but keep in mind that if you want to go to another folder like yoursite.com/anotherfolder you must to have two things (for this example):
This folder structure in your site:
[ROOTFOLDER]/anotherfolder/index.html
In this case you need to add another file called index.html because is the default path that you get when no file is specified (file being specified: yoursite.com/anotherfolder/file.html).
The HTML anchor tag must to start with a slash like Your link.
Hope it answer your question.
Note
You are talking about a path http://yoursite.com/[PATH], a subdomain is like this http://subdomain.yoursite.com.

Why does my anchor link redirect to the same page?

I faced a problem using a link inside my main html and giving another html file name to the link which is in the same root as the main html.
unfortunately after click on the link the address bar is changed but the page is not loaded and it redirects to the main html page.
this is the way I wrote the link:
click
this is my folder structure:
I also tried with giving the full path but I got this error:
Not allowed to load local resource: file:///C:/my_project/templates/PU.html
As you said in the comments, I assume you're working locally on your computer, so I'm going to answer accordingly.
The first and foremost thing to know is that your main, i.e the file you want users to see first should be named as index.html and it should be in the root directory of your project, i.e according to your question, it should be in my_project.
Now if it is as I said, then your my_project folder/directory will be considered as the root directory. With the help of this consideration, now you can set links with respect to the root directory. e.g:
click
The / at the beginning here tells the HTML to look from the root directory, i.e from my_project in your case.
I don't see any errors in the code you have. Though, I will tell you a few things here.
**./** at the beginning of the link tells HTML to look at the file in the same folder as of the present file. So, if the PU.html file is not in the same folder as of the file you're working on, it will give an error, because as I said, it's looking for the file in the same folder.
There is nothing wrong with your syntax.
click is correct,
but if you have your files in the same directory you don't need ./.

Navbar links with varying directory

my directory is shaped like this
image
in order to use my navbar between different html files, I made it into a seperate html file and use a placeholder to insert it where i need it. the problem is that now the links get thrown off.
for example: when im on the index file, the link works without a problem. however, when im in the about_us file, the link throws a cannot find in directory error because it would need ../ in front of the link.
any javascript I have also does not work for the nav.html.
any suggestions? is there a way to create links and start the directory from the root?
To navigate to the correct HTML file, you have to pass the full path of the HTML file.
For eg: If your application is running in https://localhost:8080 than you have to pass the full path as below:
Home
About Us
Or if you directly opening the HTML file in your browser without any server, than pass the full path of your project folder as below:
Home
About Us
Note: Always use the file or folder name with a hyphen - or underscore _.
For eg: instead of html files rename your folder name as html_files or html-files.

Html Image will not load under any change - Golang

I am trying to load an image locally onto my html. I first tried serving an image path through a /images/ folder, but that did not work. I then tried serving images with the whole path to the image like <img src="/Users/code/src/code/go/src/websites/website/website-Bucket.png" alt="test"> but I still had no luck. I checked my html and it has no errors. I have restarted my PC, changed the image to .jpg, and it still did not want to work. I get an error in Safari - An error occurred while trying to load the resource and the image shows as a blue box and question mark. What things would you try to troubleshoot?
Extra - I am using goLang to serve the files. I have it so a http.handleFunc() goes off and serves the images folder when it is requested. The path is showing http://localhost/images/theImage.png "the correct path" but nothing happens. So, I save the image and it shows it as a html and shows a section of the page?? Would that be a path thing?
In first instance you have to understand the path source, when you are on a HTML file, your path inside the file should be :
<img src="images/website-Bucket.png" alt="test">
that's because :
the path of your .html file can access trough files the inside path with the "/folder/file" structure route in the html file, so your structure files should be:
yourfiel.html (your file render on browser) /imagesfolder
-website-Bucket.png" (you call it on your html as
/imagesfolder/website/Bucket.png)./
you can learn more about paths here :
http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
Looks like it may be a file path issue.
Take a look at this page it has a good example.
https://www.w3schools.com/html/html_filepaths.asp
Also try renaming the image with a _ and not use the -.
Open Console in any browser and see if you see any errors that mention not being able to find the source path of the picture.
It should give you a hint of where your browser is trying to find that img.
All of your guy's responses were correct. I had the correct path. It was a Golang thing. I did not make a handlefunc when the server wants the /image.png. It was never serving the image, it just was doing nothing with it. Thank you for the responses.

Why is my picture in html not popping up on my browser

I'm trying to put this image I have saved in this location:
C:\Users\Administrator\Desktop\HTML docs\Lab 02\images
to put on my html code here:
<body>
<img src="C:/Users/Administrator/Desktop/HTML docs/Lab 02/images/logo.gif" alt="Sintok Pizza Order Form Logo" width="300" height="268">
</body>
And, yes, as you can see on the code, the image is named logo.gif
But the image doesn't show up on my browser, what am I missing here? Please point out my errors, thanks!
Prepend the path with file:///
file:///C:/Users/Administrator/Desktop/HTML docs/Lab 02/images/logo.gif
Better way is to use relative paths. Assuming your html-file is in
C:/Users/Administrator/Desktop/HTML docs/Lab 02/
You should use
images/logo.gif
as your path.
us file path like
file:///C:/Users/Administrator/Desktop/HTML docs/Lab 02/images/logo.gif
In these cases open file with any browser and the copy the path used by browser is a shortcut to test the path
You have been using the local computer path. Which is wrong. You need to use the web path.
See This : C:/Users/Administrator/Desktop/HTML docs/Lab 02/images/logo.gif
This is pointing to your C: drive which is only accessible from your computer not others. you need to put up the image path as something like
./images/logo.gif