-4

Alright. I'm coding in HTML and I have gotten stumped on a problem.

I have 3 HTML files:

main.html, buy.html, and CSS.css

and I'm trying to figure out how I can put a link or hyperlink on main.html that redirects me to buy.html.

Edit: Ive been told that buy.html and main.html have to be in the same directory. How do you add the buy.html to the same directory as main.html?

For reference, im using repl.it for coding in HTML

JROS
  • 71
  • 1
  • 2
  • 11
  • 1
    Are they in the same directory? – Andrew Li Sep 11 '16 at 17:31
  • hey Jacob, this seems like a really basic question. You probably should do more research and go through more tutorials mate. – Pragyakar Sep 11 '16 at 17:33
  • I do not believe so, trying that now. – JROS Sep 11 '16 at 17:33
  • Andrew, I am a very new HTML scripter. Should the ../buy be in CSS.css or file4.html? – JROS Sep 11 '16 at 17:36
  • Alright. When i tried Buy now., it gave me a big fat page not found. – JROS Sep 11 '16 at 17:38
  • 1
    @JacobSnyder a great tool to find solutions for 99% of beginners problems is google.com. Let's ask a question: `how to make a link to html local file`. Click first result and you've got your answer well described. Edit: assuming that they are in same directory - remove slash from your path. – Luke Sep 11 '16 at 17:40
  • @JacobSnyder if the file `buy.html` is in the same directory, you should do: `Buy now.` (without the slash). – Mouad Debbar Sep 11 '16 at 17:41
  • Lol, does anyone thinks that OP - who is obviously new to SO - will mark a an answer as the correct one? This question should be tagged because of the lack of quality! – ˈvɔlə Sep 11 '16 at 17:55

5 Answers5

0

You'd just do:

<a href="filepath">click me</a>

If you ever put this on a website though, make sure you update the link to not be a file path and make it the url it goes too.

One note, your main html file should be index.html

Editor
  • 622
  • 1
  • 11
  • 24
Joey Wood
  • 273
  • 1
  • 10
  • You'll need to specify that its a file and not a url so href="file:///filename". This will work if buy.html is in the same directory as your other files. Check [this](http://stackoverflow.com/questions/12837024/href-file-doesnt-work) out if you're still confused – Joey Wood Sep 11 '16 at 17:46
0

You can put a link to filename in file4.html like this:

<a href="buy.html">Link</a>

This, of course would only work if they were all in the same directory, otherwise, you would have to specify the relative path.

Arnav Borborah
  • 11,357
  • 8
  • 43
  • 88
  • Okay. i tried that but it stated a Page Not Found. How do i add them to the same directory? – JROS Sep 11 '16 at 17:45
0

This example will open the linked document in a new browser window/tab:

<a href="http://www.example.com/" target="_blank" title="Visit My Page">Visit My Page</a>

You can use target="_top" to break out of the frame:

<a href="http://www.example.com/html/file4.html" target="_top" title="Visit My Page">Visit My Page</a>

Useful Tips Section

Then, add a link to the bookmark ("Useful Products Section"), from within the same page:

<a href="#products" title="Visit the Useful products Section">Visit the Useful products Section</a>

Or, add a link to the bookmark ("Useful Tips Section"), from another page: Example

<a href="file4.html#products" title="Visit the Useful products Section">Visit the Useful products Section</a> 

--

<a href="page2.html" title="Link">Link</a>

If you have page2.html at the same level with folder then the path is:

<a href="../page2.html" title="Link">Link</a>
Editor
  • 622
  • 1
  • 11
  • 24
0

From your question, it seems that you want to jump to buy.html from your current page i.e file4.html. A simple anchor tag with href set to relative path(if buy.html is in same or in any of dir in current dir) or absolute path(if it is present in totally different dir structure) e.g <a href="buy.html">Click to go Buy.html</a>

0

Use <a href="buy.html">Click link here</a> the href part is the page that it will direct you to and the click link here (or whatever you want to call it) is the actual link displayed on the webpage.

If the files are all in the same folder this way is correct, otherwise you must have the file path to the .html file

Dylan
  • 454
  • 2
  • 16