Home > Web Front-end > JS Tutorial > 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
Release: 2024-10-19 19:39:02
Original
639 people have browsed it

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")
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template