Href target new window
A common request!
To open a link in a new window or tab, you can add the target
attribute to the a
tag and set its value to _blank
. Here's an example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open in new window</a>
This will open the link in a new window or tab, depending on the user's browser settings.
If you want to open the link in a new tab instead of a new window, you can use the target
attribute with the value _blank
and add the rel
attribute with the value noopener
to prevent the new tab from accessing the parent window's content:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank" rel="noopener">Open in new tab</a>
Note that the rel
attribute is optional, but it's a good practice to include it to prevent potential security issues.
You can also use the target
attribute with other values, such as:
_self
: Open the link in the same window or tab (default behavior)_parent
: Open the link in the parent window or frame_top
: Open the link in the full body of the window_frame
: Open the link in a named frame (e.g.,<frame name="myFrame">
)
Keep in mind that the target
attribute only works for links that are not already in a frame or iframe. If you're trying to open a link in a new window or tab from within a frame or iframe, you may need to use JavaScript or other techniques to achieve the desired behavior.