Home > Net >  Why is my HTML button not working when trying to switch to different section of webpage?
Why is my HTML button not working when trying to switch to different section of webpage?

Time:09-22

I am very new and I am working on my website. My hosting service is IPage. When I try changing to a different section of the website with a button it doesn't work. Here is my code:

<button onclick='https://rgulewicz2438602.ipage.com/About.html'>About</button>

CodePudding user response:

onclick is call for a event, so u need put an action on him, not url. To redirect to another page you can use window.location, like this:

<button onclick='window.location="https://rgulewicz2438602.ipage.com/About.html"'>About</button>

CodePudding user response:

You should use an anchor tag to change the location of a page, like so:

<a class="btn" href='https://rgulewicz2438602.ipage.com/About.html'>About</a>

then you can style it using css to look like a button

some example styles might be something like:

.btn {
  display: inline-block;
  padding: 4px 8px;
  background: tomato;
  color: white;
  text-decoration: none;
}

CodePudding user response:

To open a site use either window.open with JavaScript or better still use a link which has an attribute of target="_blank"

Try this:

a {
  background: #aaf;
  border: 1px solid #000;
  border-radius: 3px;
  color: #000;
  padding: 4px;
}
a:hover {
  background: #ddf;
}
a:active {
  background: #aaf;
}
<a href="https://rgulewicz2438602.ipage.com/About.html">About</a>

  • Related