Jack Edwards
Jack Edwards

Reputation: 53

Button link doesn't work

Ok, so I have a button and I wan't to link it through to one of my pages. This piece of code used to work, but nolonger seems to. Is there any error in this code?

div align="center">
<button onclick="location.href='/game.html'">
Download</button>

Thanks!

Upvotes: 1

Views: 11889

Answers (2)

Sean Carroll
Sean Carroll

Reputation: 107

Nothing wrong with your code except a missing < at the front of it.

eg.

<div align="center">
<button onclick="location.href='/game.html'">Download</button>

also you shouldn't need the / before game unless your specifying a sub path eg. ../ or ../../

eg.

<div align="center">
<button onclick="location.href='game.html'">Download</button>

or

<div align="center">
<button onclick="location.href='../game.html'">Download</button>

and so on.

Upvotes: 1

Oussama Elgoumri
Oussama Elgoumri

Reputation: 617

  1. you are not using a local server, run python -m SimpleHTTPServer from the folder that holds your project, then access it using localhost:8000

  2. if the first solution is not available for you, then just provide the full path to the target page, like so C:/Users/Name/Desktop/Website/games.html, which is a bad idea, because the path is not portable, it's hardcoded, and it will only work from that location.

Upvotes: 0

Related Questions