Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open a new tab or window when a link is clicked?

I have same ancors/hyperlink in my html file. These point to a new website outside my site. So I want that when the user clicks the link it should open a new tab or window. My website page should not be closed.

How can it be done?

like image 215
user177785 Avatar asked Nov 30 '22 11:11

user177785


2 Answers

open in tabs: there is nothing programatically that you can do to accomplish that, the only thing I'm thinking of is set the browser to open new links in tabs instead of new window...

to open in a new window all you need is to place a target in your anchors

<a href="mydomain.com" target="_blank">click here</a>

and, by the way there are more options to the target

target="_blank"   

opens in a new Blank window

target="_parent"  

opens in a Parent window (used when dealing with iframes and you want to open the link in other frame)

target="_self"    

opens in it's own/self window (used when dealing with iframes and you want to open the link in the current frame)

target="_top"     

opens in the top of all frames (it will open on top of all frames in the page, like a no-frame page will be display)

like image 89
balexandre Avatar answered Mar 07 '23 11:03

balexandre


<a href="newpage.htm" target="_blank">Click me to open in a new tab/window</a>

Load the linked document into a new blank window. This window is not named.

If there is no existing window or frame with the same name as specified in the target, a new window is opened with a name equal to the value of the target.

Its the setting in a browser that determines whether to open the page in a new tab or in a new window.

like image 44
rahul Avatar answered Mar 07 '23 11:03

rahul