Generally, when we click on a link to a page in most of the websites, it will open the new page in the current tab. It is the general scenario of websites. But sometimes, it is more effective and user friendly to open the link of a page in a new tab.
For example, a web page has a list of seven wonders of the earth. When a user clicks on any one wonder of the planet, it should be opened in a new tab. Suppose it will provide detailed information about that place. After reading that page, users can open information about other places.
Note: In the above example, if the website opens a new page on the same tab, then the user finds difficulties while accessing the site.
In HTML, when we use <a> tag to create a link on some text or an image, it usually will open a new page on the same tab.
Example 1
<!DOCTYPE html> <html> <body> <a href="https://www.errorsea.com">Visit errorsea.com</a> <p>Above link will open in same tab.</p> </body> </html>
Explanation
When we click on the link Visit errorsea.com, it will open the link in your web browser’s same tab.
The target attribute will decide whether the link will open on the same tab or in a new tab. The target attribute has different values; it will determine the result — for example, _blank, _self, _top, _parent, etc.
The _blank is used for opening the link in a new tab.
Let us consider the following code; it will generate a link that will open in a new tab.
Example 2
<a href=”https://www.errorsea.com” target=”_blank”>Visit errorsea.com!</a>
Explanation
The above code will open the errorsea.com website in anew tab of your browser.
Example 3
<!DOCTYPE html> <html> <body> <a href="https://www.errorsea.com" target="_blank">Visit errorsea.com!</a> <p>Above link will open in a new tab.</p> </body> </html>
Explanation
Here we set the target attribute to _blank, and then it will open the link in a new tab.
We can also use the following values of the target attribute and create different results according to the value.
Read Also: JavaScript Operators
This all about _blank method of the target attribute. We should use this method to provide detailed information on some topics because it will make the website more useful and user-friendly. User can come back to the previous page at any time, or he/she can visit different pages of the same website at the same time.
There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…
In this tutorial, I'm going to show you how to install MySQL on your computer.…
Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…
We can redirect any webpage to any other or redirect the whole domain or website…
There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…
Include files in PHP are used in appending various global or config files. We can…