Home > Web Front-end > JS Tutorial > body text

How to Open Hyperlinked URLs in Same Tab Using window.open

Susan Sarandon
Release: 2024-10-19 19:43:30
Original
1001 people have browsed it

How to Open Hyperlinked URLs in Same Tab Using window.open

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!