I have a folder named "myWebsite".
Inside that folder I have "index.html" and another folder named "other". Inside "other" I have CSS files JS files and "page2.html". I have linked all files with my "index.html". But when I am in "page2.html", I want a link that will lead me to "index.html".
go back
In order to navigate back you should use '../' if you want point two folders back you can use '../../' for instance.
In this case, within Page2.html use:
<a href="../index.html">go back<a>
NOTE: You have an extra dot.
Based on what you wrote, this should fix it:
link
The ../ directory references the parent directory.
Examples:
<a href="sample.html"> The "sample.html" file is located in the same folder as the current page.
<a href="pages/sample.html"> The "sample.html" file is located in the pages folder in the current folder.
<a href="/pages/sample.html"> The "sample.html" file is located in the pages folder at the root of the current web.
<a href="../sample.html"> The "sample.html" file is located in the folder one level up from the current folder.
See here for more on HTML filepaths.
Related
My Javascript wont activate on dreamweaver. I attached it and everything but when i try to call it with script tags it does not appear on my live preview. i have it attached by this code
<script src="file:///C:/Users/Matthew/Desktop/Untitled-2.js" type="text/script"></script>
If someone could please help that would be awesome! :D
Live mode runs Your code in some virtual webserver and it cannot get local js file. Since browser may block resource from sharing (CORS). Think about putting js file to relative to html file and defining relative url to js file. Create js folder near to html file and put js file there and in Your html file define src="js/Untitled-2.js" – num8er 12 mins ago
Thanks Num8er
In my opinion, it is best practice to keep all files relative to the project. This means setting up a project folder and keeping files organised in sub-folders.
Consider this project structure:
Project folder
CSS folder
style.css
Javascript folder
script.js
Images folder
image.jpg
index.html
The sub-folders are directly children of the project folder, and inside each folder is the corresponding files.
The html file is also a direct child of the project folder (it's not in any other folder).
This means all the related files are relative to the html file.
So in your html file, you can link up these files easier.
<link href="CSS/style.css" rel="stylesheet">
<script src="Javascript/script.js" type="text/javascript"></script>
<img src="Images/image.jpg">
As you can see all the files are linked without a full path, this is called relative linking. Absolute linking is the opposite in which you specify the full path, such like you are doing at the moment:
<script src="file:///C:/Users/Matthew/Desktop/Untitled-2.js" type="text/script"></script>
This is good in certain places, however you should always try to aim for relative linking. If you follow this, you shouldn't have any more problems.
So Im trying to link a local copy of bootstrap (It works with a CDN). I have bootstrap.css installed in the same directory as index.ejs and yet I keep getting these 404 errors.
So the file path for bootstrap.css is /home/daniel/scheduler/doc_display/app/bootstrap.css
and index is: /home/daniel/scheduler/doc_display/app/index.ejs
Any help would be much apreciated
Your browser is going to look for the file relative to the location of the page it loads, so you need to make sure your path is correct.
Right now it's looking for it in the same folder as the index, which it looks like isn't where it's located.
I put the bootstrap.css file inside of my dist directory then included the new path inside the link tag. For some reason webpack seems to find paths when they are in the dist directory
I am facing difficulty in understanding relative path concept, I have seen a part of code written as
../../abc/file/images/picutre/down.gif
how the relative path is computed
A relative path is a path relative to the working directory. In other words the starting point to look for files is from the working directory.
The "../" in a relative path means to go up one directory.
So lets say you're referencing the relative path ../../abc/file/images/picutre/down.gif from an index.html page in the following structure :
http://someexampleurl.com/dir1/dir2/index.html
Your working directory when working from index.html is /dir2 so taking into account that you're going up two levels, the browser expects the file to be at:
http://someexampleurl.com/abc/file/images/picutre/down.gif
how the relative path is computed
Basically a relative path is a "map" from the directory that you are located to the file you need to include. Therefore, relative path is computed based on where you want to go.
For example you have a structure
/ (document root)
|--home.php
|--t.php
|--common
|--header.php
|--footer.php
|--support
|--index1.php
|--privacy
| |--index2.php
From home.php you need to include header and footer. Therefore your home code will look like
<?php
include("common/header.php"); // go one folder down (common) and grab the file header.php
include("common/footer.php"); // go one folder down (common) and grab the file footer.php
Now let say you are in index1.php in support and you need header.php and footer.php. You code will look like
<?php
include("../common/header.php"); // go one folder up (common) and grab the file header.php
include("../common/footer.php"); // go one folder up (common) and grab the file footer.php
Think folder inside folder as levels (level1, level2, etc)
Note: Be careful with relative paths something they are a pain.
it says go back up two level (parent directory) "../../" from current location.
So if we are on https://example.com/my/path/here and it loaded a file ../../abc/file/images/picutre/down.gif then we would go up 2 directories because of the 2 ../'s to https://example.com/my. Then we would go down to /abc/file/images/picutre/down.gif. So the final destination would be https://example.com/my/abc/file/images/picutre/down.gif
down.gif is present in the same directory
/ starts form root directory
../ one directory back from current directory
../../ two directory back from current directory
I have a website where I am referencing the CSS/JS in the root directory. I want to create a sub-section of the website under it's own directory. The problem is that I am referencing the
CSS/JS in the main directory and I want to know what the best way to reference the CSS/JS would be for the subdirectory.
If I just use the http address for the files it works, but I think there could be a better way to go about this. Does anyone have any opinion on the matter?
You can use ../ to specify the parent directory when using relative paths. So for example, if your file structure is something like this:
root
index.html
style.css
javascript.js
subdirectory
subpage.html
Then in your subpage.html file, use:
<link rel="stylesheet" href="../style.css">
<script src="../javascript.js"></script>
my folder structure is as follows:
sample/register
i have a file in sample folder named index.html .i want to redirect to this file from a file within register folder.how can i do that? this is what i have done.But the problem is that i have a file within register folder named index.html and its getting redirected to this folder.how do i mention the root folder?
<li><a id="register" href="index.html">Back</a></li>
Depending on where your root folder is href="/index.html" may work or just going up one folder with href="../index.html"