Reputation: 21
So, currently I'm making a website. It's an assignment. And when I tried to open it on different computer, it didn't work.
So, for example: "a href="file:///E:/assignment/main page/index.html#"
It did work on my computer, but it won't work on another. I need it to work at any computer.
Upvotes: 0
Views: 210
Reputation: 3338
There are two halves to your question:
How do I make my website accessible anywhere?
You need a web server, or you need to use a hosting company. GoDaddy, 1and1, HostGator, and other hosting companies have computers (web servers) that are configured to show their webpages to anyone in the world. They cost around $10 per month, and you end up with the ability to create links such as http://example.com/myproject/index.html
It's possible that your professor will let you put your web pages on one of his drives that are accessible anywhere on campus. Otherwise, a flash drive can do in a pinch. Put the files onto a flash drive and then bring the flash drive to class.
Is there a better way to write links?
Most websites use relative URLs in their links. For example, Stack Overflow, instead of writing every link as http://stackoverflow.com/whatever
, will usually use a relative URL instead: /whatever
.
There are a few simple rules that your browser follows when turning an href
tag into a web address (in this example, we're starting from this page: http://stackoverflow.com/questions/15078748/how-to-make-working-path-in-html#15078792
)
http://
(or anything else that comes before
a ://
), then your browser will take you exactly there. For example:
http://stackoverflow.com
takes you to the Stack Overflow home page./
, then the browser will take you out of
any subfolders before executing the rest of the link. For example:
/election
will take you here: http://stackoverflow.com/election
../
, then it will send you exactly one folder
up. This can be done multiple times. For example. ../
will send you
here: http://stackoverflow.com/questions/
. ?
, &
, #
) then it will usually append
this to whatever page you are currently on. #example
would take you
to
http://stackoverflow.com/questions/15078748/how-to-make-working-path-in-html#example
.example
will send you here:
http://stackoverflow.com/questions/15078748/example
Upvotes: 1
Reputation: 2889
In simple words, you have to write:
<a href="./index.html">...</a>
to link to index.html a page which is in the same directory as your file index.html;
examples:
./my_page.html
use the "./" for linking pages in the same directory;
if the source and dest pages are in different folders, you shall use:
../my_page.html
or
./folder_path/my_page.html
according to the relative paths of the pages.
Upvotes: 0