Open URLs within the Same Tab and Window
When working with hyperlinks, developers often encounter situations where they want to open the linked resource in the same tab as the page containing the link. Using window.open by itself accomplishes the task of opening the link, but it does so in a new tab.
Solution:
To achieve the desired behavior, developers must specify the name attribute in the window.open command. By setting the name to _self, the link will open in the same tab as the original page.
Updated Code:
window.open("https://www.youraddress.com","_self")
Note:
It's important to remember that the URL should be prepended with the appropriate protocol (e.g., https://). Otherwise, the browser will attempt to open the link as a relative URL. This solution has been tested successfully in Chrome 59, Firefox 54, and IE 11.
The above is the detailed content of How to Open Hyperlinked URLs in Same Tab Using window.open. For more information, please follow other related articles on the PHP Chinese website!