Open page in the same window

-2

I have a button where I would like it to point to another page when clicked and the alternative that I found was using the om click, but it happens that it opens in another window and I need it to open in the same window.

How do I open in the same window?

<button type="submit" onclick="window.open('menu.html')">Login</button>
    
asked by anonymous 19.08.2018 / 23:40

1 answer

1

Use window.location.href='' instead of window.open('menu.html') , window.open will open a new window and this is not what you want ...
You can also use window.location.replace('menu.html') , but it will replace the current page in the browser history, making it not possible to return to the page after clicking the button.

Option 1 window.location.href='' :

<button type="submit" onclick="window.location.href='menu.html'">Login</button>

Option 2 window.location.replace() :

<button type="submit" onclick="window.location.replace('menu.html')">Login</button>

Option 3, a button made of link.

.btnlogin {
    background:#000;
    border-radius:4px;
    padding:4px 6px;
    color:#fff;
    text-decoration:none;
}
<a href="menu.html" class="btnlogin">Login</a>
    
19.08.2018 / 23:59