-1
I would like to know how to open a new html file in the same tab, but by command. I’ve used window.open(), but it keeps the tab open and opens a new one.
I would not like to use the tag "a"
-1
I would like to know how to open a new html file in the same tab, but by command. I’ve used window.open(), but it keeps the tab open and opens a new one.
I would not like to use the tag "a"
4
You can also change the location using Location.replace
location.replace("nova url");
function replace() {
location.replace("https://answall.com", "_self");
}
<button id="replace" onclick="replace()">Clique em mim para substituir a url</button>
3
Use window.open("seuURL", "_self");
Mozilla documentation about this
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
<button onclick="funk()">Abrir</button>
<script>
function funk() {
window.open("https://answall.com", "_self");
}
</script>
1
Use window.open
to open a page in the same tab, in my view, it does not make much sense, if the main function of this method is to just open a new tab.
You could use location
in the onclick
. It doesn’t take much of a function for that, and you can do it all on the button itself in a more simplified way:
<button onclick="location = 'outra_pagina.html'">Ir</button>
The location
will redirect the page to where you want, be it an internal page or an external website. Only to go to an external site, you need to put the protocol (ex., https://
). Ex: location = 'https://google.com'
.
Browser other questions tagged javascript html5 commands
You are not signed in. Login or sign up in order to post.