Ask coding questions

← Back to all posts
Code not working. Please help
Satkrithi (0)

In the file contact.html i put a button link called go back to main page and gave the link as index.html:

<button class="GFG" 
onclick="window.location.href = 'index.html';">
 Go Back to main page
</button>

This is the code but it is not working.
Please help

Answered by codingjlu (483) [earned 5 cycles]
View Answer
Comments
hotnewtop
codingjlu (483)

Don't do a button; use a link - you can style one to look like a button, something like this CSS:

#btn {
   text-decoration: none;
   padding: 5px 10px;
   background-color: #4287f5;
   color: white;
   outline: none;
   border: none;
   border-radius: 5px;
}
<a id="btn" href="/index.html">Hello world!</a>

Result:

You just got a nice looking "button". Also, this is the correct/traditional way to do it. An actual button would not let you open in a new tab, and it doesn't act as a link, and it breaks the back button.

Satkrithi (0)

@codingjlu Thank you so much for the help.(¬‿¬)

FishballNooodle (211)

Sure about this
But you can create an <a> tag and remove the text decorations, add border and it will look like a button.
Then you can use href="index.html"

FishballNooodle (211)

@Satkrithi
text-decorations:None
border : 10 5 10 5
border-radius: 10px

Satkrithi (0)

@FishballNooodle are you sure? I have tried doing it but it is still not working

Coder100 (18915)

It is not working because some of your pages don't have any code.
For example, Thank you contact.html and Topics.html.

Satkrithi (0)

@Coder100 In that case, it would show blank page but here it is showing page not found.