I am trying to open a link in the same window that I am working on but it doesn't work I get the message in the attached photo
<body>
<form>
<select name="list" id="list" accesskey="target">
<option value='none' selected>Choose a theme</option>
<option value="https://google.com">Google</option>
<option value="https://www.youtube.com">Youtube</option>
<option value="https://www.facebook.com/">Facebook</option>
</select>
<input type=button value="Go" onclick="goToNewPage()" />
</form>
<script>
function goToNewPage(){
window.open(list.value, '_self')
}
</script>
</body>
CodePudding user response:
You should use
window.open(url,'_blank')
CodePudding user response:
Use window.location = "Url" for that.
function action() {
window.location = "https://stackoverflow.com/questions/72602788/html-open-link-in-the-same-window-not-a-new-tab"
}
<button onclick="action()">klick</button>
https://developer.mozilla.org/en-US/docs/Web/API/Window/location
CodePudding user response:
You can go for
window.location.href=url
CodePudding user response:
here's what you can do with window.open
URL is loaded into a new window, or tab. This is the default
window.open(list.value, '_blank')
URL is loaded into the parent frame
window.open(list.value, '_parent')
URL replaces the current page
window.open(list.value, '_self')
URL replaces any framesets that may be loaded
window.open(list.value, '_top')