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

JavaScript canvas implements graphics and text with shadows

Use canvas to create graphics and text with shado...

How to install MySQL 8.0.17 and configure remote access

1. Preparation before installation Check the data...

How to set password for mysql version 5.6 on mac

MySQL can be set when it is installed, but it see...

CSS3 realizes the animation of shuttle starry sky

Result: html <canvas id="starfield"&...

Bootstrap FileInput implements image upload function

This article example shares the specific code of ...

Tutorial on how to create a comment box with emoticons using HTML and CSS

HTML comment box with emoticons. The emoticons ar...

Two ways to declare private variables in JavaScript

Preface JavaScript is not like other languages ​​...

In-depth understanding of the creation and implementation of servlets in tomcat

1. What is a servlet 1.1. Explain in official wor...

Learning to build React scaffolding

1. Complexity of front-end engineering If we are ...

How to Dockerize a Python Django Application

Docker is an open source project that provides an...

Debian virtual machine created by VirtualBox shares files with Windows host

the term: 1. VM: Virtual Machine step: 1. Downloa...

Linux swap partition (detailed explanation)

Table of contents linux 1. What is SWAP 2. What d...