HTML implements the function of automatically refreshing or opening a new window for the URL link of the a element href

HTML implements the function of automatically refreshing or opening a new window for the URL link of the a element href

Sometimes we want to implement such a function: click a link. If the link has been opened in the browser, refresh the opened link window; if the link has not been opened, open the link page in a new window.

This is a very good experience enhancement feature that can effectively avoid opening duplicate and redundant pages in browser tabs.

The key is how to achieve it?

Use the target attribute of the a tag:

Both the a link element and the form element have an attribute called target. The supported values ​​include the following:

  • _self: Default value. The current browser context.
  • _blank: Usually a new tab, but users can configure their browsers to open in a new window.
  • _parent: The parent context of the current browser context. If there is no parent, it behaves like _self.
  • _top: The topmost browser context. If there is no ancestor context, behaves like _self.

In fact, target has a hidden feature, which is that it can be specified as a specific URL address or any custom name.

For example:

<a href="http://www.baidu.com" target="http://www.baidu.com">Blank page</a>

At this time, if the browser already has a tab with the address blank.html, clicking the above link will not open a new window, but will directly refresh the already opened blank.html; if there is no tab with the address blank.html in the browser, the behavior of the target attribute is similar to '_blank'.

In other words, if we want to achieve the requirement of automatic refresh of link address and opening of new window, we just need to set the target attribute value of link element and form element to the target URL address value.

Therefore, if you want to use one tab for all search results pages, you need to use other methods. It is very simple. Just specify the same value, for example:

<a href="blank.html?s=1" target="_search">blank page?s=1</a>
<a href="blank.html?s=2" target="_search">blank page?s=2</a>

As you can see, href="blank.html?s=1"和href="blank.html?s=2" will point to the same page and will not open two new windows.

Summarize

To achieve the function of automatic refresh of the a element href link or opening in a new window, you only need to set the target attribute value to the same as the href attribute value.

This feature is supported by IE, Firefox, and Chrome, so you can use it with confidence.

This is the end of this article about how to implement automatic refresh or new window opening of URL links of a element href in html. For more relevant content about how to implement automatic refresh or new window opening of URL links in html, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<: 

>>:  CSS complete parallax scrolling effect

Recommend

An article to quickly understand Angular and Ionic life cycle and hook functions

Table of contents Angular accomplish Calling orde...

Detailed explanation of several ways to install CMake on Ubuntu

apt install CMake sudo apt install cmake This met...

Execute the shell or program inside the Docker container on the host

In order to avoid repeatedly entering the Docker ...

Summary of Binlog usage of MySQL database (must read)

I won't go into details about how important b...

Who is a User Experience Designer?

Scary, isn't it! Translation in the picture: ...

How to deploy LNMP & phpMyAdmin in docker

Environmental preparation: Deploy lnmp on a host ...

mysql implements the operation of setting multiple primary keys

User table, ID number must be unique, mobile phon...

Design Tips: We think you will like it

<br />Looking at this title, you may find it...

Parsing Apache Avro Data in One Article

Abstract: This article will demonstrate how to se...

How to implement Docker to dynamically pass parameters to Springboot projects

background Recently, some friends who are new to ...

VMware, nmap, burpsuite installation tutorial

Table of contents VMware BurpSuite 1. Virtual mac...

Three ways to check whether a port is open in a remote Linux system

This is a very important topic, not only for Linu...

W3C Tutorial (4): W3C XHTML Activities

HTML is a hybrid language used for publishing on ...