Open link in a new window

The first thing we have to know if we think about opening a link in a new window is that it is an option configurable by browsers in their default behavior and that the most normal thing is that the links on a page HTML will be on the same page that contains them. But it may be the case that this is not what interests us the most and we want to change their behavior.

If what we want is to open the link in a new window we simply have to work with the attributes of the element

a
or anchor of HTML. Specifically with the values ​​that we assign to the attribute

target

.

That is, our code to create a link will look like this, using the following structure:

<a href="link" target="value">Bindable Content</a>

We have to know the values ​​that can be given to the attribute

target

there are several. Among them we can find the following:

  • _blank, the link opens in a new page.
  • _parent, the link opens on the parent page.
  • _self, the link opens on the same page.
  • _top, the link opens above the top window. In this case it is if we are in a frame or iframe. It would open on the page that contains it.

So if we want to open the link in a new window we must assign the value of _blank to said tribute, so that when we click on the link, the link opens in a new window.

That is why our code to create the link will be the following line of code:

<a target="_blank" href="<http://www.lineadecodigo.com>">Open Line of Code in a new window</a>

In this simple way we can achieve the purpose we were looking for within the design of our website.