22

I have this hyperlink code:

<a href="http://www.youtube.com/user/mamgrow"><img style="position:relative; float:right; height:30px; left:-30px;"  alt="mamgrow facebook" src="images/facebook.png"/></a>

And I want this link to open in a new tab...

I tried to put this in:

style="target-new:tab;

But it didn't work. Any ideas?

2

4 Answers 4

51

You can easily use the target attribute like:

<a href="http://www.example.com" target="_blank"><img src="your/image" /></a>

If your user has a browser which support tabs, the linked page will opened at a new tab in the active browser window, if set so - mostly it is a default.
Nearly every browser supports this today. See this list on Wikipedia for detailed informations.

Here a list of the target attribute properties in a <a> tag in HTML:

target="_blank" <!-- opens link in a new window -->
target="_self" <!-- opens link in actual window -->
target="_parent"
target="_top" <!-- both handle frames -->

This part of your code:

style="target-new:tab;

has no effect, its seems to be not supported by any modern browser.

5

Reading the w3schools instructions explains that the syntax for opening a link in a new tab or window (depending on the settings in the web browser) you should add the attribute

target="_blank"

http://www.w3schools.com/html/html_links.asp

3

You should be using the following code to open in a new window

<a href="http://www.google.com" target="_blank">...</a>
0

Expanding upon @ztirom's answer...

Mozilla Developer Network says:

target

Specifies where to display the linked URL. It is a name of, or keyword for, a browsing context: a tab, window, or <iframe>. The following keywords have special meanings:

  • _self: Load the URL into the same browsing context as the current one. This is the default behavior.

  • _blank: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead.

  • _parent: Load the URL into the parent browsing context of the current one. If there is no parent, this behaves the same way as _self.

  • _top: Load the URL into the top-level browsing context (that is, the "highest" browsing context that is an ancestor of the current one, and has no parent). If there is no parent browsing context, this behaves the same way as _self.

Note: When using target, consider adding rel="noopener noreferrer" to avoid exploitation of the window.opener API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.