Home  >  Article  >  Web Front-end  >  How to Open a URL in the Same Window and Tab in HTML5?

How to Open a URL in the Same Window and Tab in HTML5?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-19 19:39:02554browse

How to Open a URL in the Same Window and Tab in HTML5?

Open URL in the Same Window and Tab

Opening a URL in a new tab can often disrupt user experience. To open a link in the same window and tab that contains the page with the link, use the window.open function with the _self parameter.

For example:

window.open("https://example.com", "_self")

This line of code will open the URL "https://example.com" in the same window and tab where the original page is displayed.

Note that starting with HTML5, the window.open function requires an absolute URL (prepended with a protocol). Without it, window.open will try to open the URL relative to the current page, which may not be the desired behavior.

The above is the detailed content of How to Open a URL in the Same Window and Tab in HTML5?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn