- Make a link open a new window (not tab) [duplicate]
- 5 Answers 5
- HTML option
- JavaScript option
- How to Make Links Open in a New Window or Tab
- HTML code for opening links in a new browser tab or window
- How to Make Links Open in a New Window or Tab
- Prerequisites
- How to Open Hyperlinks in a New Browser Tab or Window
- It Doesn’t Have the Benefit You Think It Confers
- It Makes Your Site Vulnerable to Phishing Attacks
- Conclusion
- thesitewizard™ News Feed (RSS Site Feed)
- Please Do Not Reprint This Article
- Open link in new tab or window [duplicate]
- 4 Answers 4
- Open links in new window using AngularJS
- 7 Answers 7
- Old Answer
- Not the answer you’re looking for? Browse other questions tagged javascript angularjs or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Sharepoint links — how to open in new tab/Window
- 7 Answers 7
Make a link open a new window (not tab) [duplicate]
Is there a way to make a link open a new browser window (not tab) without using javascript?
5 Answers 5
With pure HTML you can’t influence this — every modern browser (= the user) has complete control over this behavior because it has been misused a lot in the past.
HTML option
You can open a new window (HTML4) or a new browsing context (HTML5). Browsing context in modern browsers is mostly «new tab» instead of «new window». You have no influence on that, and you can’t «force» modern browsers to open a new window.
In order to do this, use the anchor element’s attribute target [1] . The value you are looking for is _blank [2] .
JavaScript option
Forcing a new window is possible via javascript — see Ievgen’s excellent answer below for a javascript solution.
(!) However, be aware, that opening windows via javascript (if not done in the onclick event from an anchor element) are subject to getting blocked by popup blockers!
[1] This attribute dates back to the times when browsers did not have tabs and using framesets was state of the art. In the meantime, the functionality of this attribute has slightly changed (see MDN Docu)
[2] There are some other values which do not make much sense anymore (because they were designed with framesets in mind) like _parent , _self or _top .
How to Make Links Open in a New Window or Tab
HTML code for opening links in a new browser tab or window
How to Make Links Open in a New Window or Tab
I was asked by a visitor how he could make hyperlinks on his website open a new browser window or tab when clicked. This article answers that question.
Prerequisites
Since the visitor did not specify which web editor he was using, I will assume here that he is working directly in HTML.
Note that this does not mean you cannot follow this tutorial if you use a visual web editor, or if your website uses some sort of blogging software. It merely means that you will need to somehow access the HTML code of your page so that you can modify it. Most web editors and blogging software allow you to do this.
For example, if you are using Expression Web, you can modify the HTML code of your web page by switching to the Code mode. Instructions for this can be found in the article How to Insert HTML Code into a Web Page with Expression Web. Similarly, Dreamweaver users can follow the steps given in How to Insert Raw HTML Code in Dreamweaver, BlueGriffon users the tutorial How to Insert HTML Code in BlueGriffon, and KompoZer users the guide How to Insert HTML in KompoZer.
How to Open Hyperlinks in a New Browser Tab or Window
The short answer is: just add a target=»_blank» attribute to your links (anchor tags).
For example, if you have a link that says the following:
Change the above so that it now says:
Now when your visitors click that link, it will open in a new window or tab (depending on which web browser they are using and how they configured that browser).
Note that if your web page uses the «strict» DOCTYPE of XHTML 1.0 or 1.1, you will not be able to do the above and still have your page validate as correct. However, I suspect virtually nobody uses those, so don’t worry if you don’t understand what I just said in this paragraph. The «transitional» versions of those DOCTYPEs are fine, though, since the target attribute is still supported there.
If you are using Expression Web, Dreamweaver, BlueGriffon or KompoZer, just click somewhere in the link that you want to modify, switch to the mode that allows you to change the HTML code (see the tutorials listed earlier in the Prerequisites section to find out how to do this), and add the target=»_blank» attribute.
It Doesn’t Have the Benefit You Think It Confers
I know that some new webmasters seem to have got the impression that causing external links to open in a new window helps to keep people from leaving your website. This is an erroneous assumption. If someone clicks on a link and wants to return to your site, they will simply hit the Back button on their browser. Most people, even non-computer-geeks, learn this feature of their browser within a short time of discovering the Internet. The power users learn, in addition, how to right click a link and select «Open in a new tab» (or window) when they need a link to be displayed in a separate tab or window.
When you create links that open in a new window, you are actually preventing newcomers from returning to your website. You may think that they will know how to simply switch back to the original window. My experience with such people suggests otherwise; they are stymied by the Back button not working, and are not even aware that they are looking at a new tab or window. When they can’t figure out how to solve the problem, they will give up and move on to other things.
The situation is not better with experienced users. While they can figure out that they are looking at a new tab or window, and can switch back, they tend to get very irritated at your site for opening windows without their permission. After all, they are power users: if they wanted to open a new window, they will open it themselves; they don’t want you to do it without their consent. It’s worse if all your links open in new windows (leading to the comedic situation described in my article about usability mistakes made by amateur webmasters).
It Makes Your Site Vulnerable to Phishing Attacks
At the time this is written, when you open a new page with target=»_blank» , the site you link to gains access to the window/tab containing your page and is able to change it (in the visitor’s browser) to display a different web address.
This not only thwarts your attempt to keep visitors at your site (if that’s your purpose), it’s also a potential danger to them. For example, if you have a login page, the linked-to site may replace it with one on another site that looks like yours, but actually collects your visitor’s login details. This kind of attack is called «phishing». Even if your site does not have facilities for visitors to log in, the linked-to site can replace it with a page that delivers malware.
This vulnerability is not hypothetical. The people from the Google Security Team have noted a «significant number of reports» of such «tabnabbing» being used to deliver malware.
Technical details (only for those who are interested): the newly open site gains limited access to your page via the JavaScript window.opener object. This is a read/write object that they can manipulate. It has a property called window.opener.location that can be changed, causing the browser to go to a new URL instead of staying at your page. If you don’t understand this paragraph, skip it. It’s merely the technical version of the explanation given earlier.
You can prevent it from happening in some browsers by adding rel=»noopener noreferrer» to your link. With this added, the above example becomes:
Theoretically, either rel=»noopener» or rel=»noreferrer» is sufficient to prevent this problem, with rel=»noopener» being the correct attribute to use. (The other one, rel=»noreferrer» , has a side-effect in that the browser will also withhold the referring URL.) However, at this time, not all browsers support rel=»noopener» . Likewise, rel=»noreferrer» is also not supported by some browsers. Since the list of browsers that support either attribute is not identical, if you want this protection from the greatest subset of browsers possible, you will probably need to use both.
That said, the workaround only helps with the later versions of Chrome, Firefox and Safari. Internet Explorer does not have such a facility, although from my cursory test, version 11 seems to be immune to the attack in its default security zone. I’m not sure about Microsoft Edge.
In other words, the method detailed above is not 100% foolproof. The best way to avoid the problem is to use normal links, without target=»_blank» .
Conclusion
My general recommendation is to avoid opening links in a new window or tab, if possible. Of course there may be specific instances where this is needed (which is why such a facility exists in the first place, for those rare cases where it may be required). If so, you may want to warn your visitors by saying something like «opens in a new window» next to your link (if it’s appropriate). It won’t help the average Internet user, who won’t know what you are talking about or how to deal with it, and it won’t guard them from attacks using your site, but at least you will won’t irritate the more experienced Internet visitors.
Copyright © 2015-2019 Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from https://www.thesitewizard.com/.
thesitewizard™ News Feed (RSS Site Feed) 
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
Please Do Not Reprint This Article
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
Open link in new tab or window [duplicate]
Is it possible to open an a href link in a new tab instead of the same tab?
4 Answers 4
You should add the target=»_blank» and rel=»noopener noreferrer» in the anchor tag.
Adding rel=»noopener noreferrer» is not mandatory, but it’s a recommended security measure. More information can be found in the links below.
It shouldn’t be your call to decide whether the link should open in a new tab or a new window, since ultimately this choice should be done by the settings of the user’s browser. Some people like tabs; some like new windows.
Using _blank will tell the browser to use a new tab/window, depending on the user’s browser configuration and how they click on the link (e.g. middle click, Ctrl +click, or normal click).
set the target attribute of your element to «_tab»
EDIT: It works, however W3Schools says there is no such target attribute: http://www.w3schools.com/tags/att_a_target.asp
EDIT2: From what I’ve figured out from the comments. setting target to _blank will take you to a new tab or window (depending on your browser settings). Typing anything except one of the ones below will create a new tab group (I’m not sure how these work):
Open links in new window using AngularJS
Is there a way to tell AngularJS that I want links to be opened in new windows when the user clicks on them?
With jQuery I would do this:
Is there an equivalent with AngularJS?
7 Answers 7
Here’s the same concept made less invasive (so it won’t affect all links) and more adaptable. You can use it on a parent element to have it affect all children links. Live demo (click).
Old Answer
It seems like you would just use «target=»_blank» on your tag. Here are two ways to go:
You could just use window , but it is better to use dependency injection, passing in angular’s $window for testing purposes.
It works for me. Inject $window service in to your controller.
this is the code of your button
in the controller just add this function.
@m59 Directives will work for ng-bind-html you just need to wait for $viewContentLoaded to finish
I wrote a small gist which I think can be very helpful to anybody seeking a solution to that problem: external link
What it does is it adds target=»_blank» attributes to anchor elements that would link to a domain different than the current one. You can patch it up to whatever you see fit.
I have gone through many links but this answer helped me alot:
** data will be absolute url which you are hitting.
Not the answer you’re looking for? Browse other questions tagged javascript angularjs or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Sharepoint links — how to open in new tab/Window
I’ve noticed with Sharepoint 2010, many of the links do not the support open in new tab/window feature. For example, items on the quick menu do not. Is it possible to enable?
7 Answers 7
Whats the ‘Quick menu’? Do mean list item context menu or something else? Can you post a screenshot?
There are two types of links used.
Normal HTML anchors — You can hold down the CTRL key when clicking.
JavaScript links (menus and such) the CTRL key doesn’t work. If you’re working with the Edit/View forms then this may be of interest
Especially look for Part II where it talks about changing this behaviour in List Settings > Advanced Settings > Dialogs
Use the JavaScript function to open a new window in SharePoint 2010.
Create the function to open your target window as sample provide below.
Place the function load_url in JavaScript file
Click site actions, select manage content and structure. Suppose you want to change the links in the page http://someserver/sites/Dev/Help/HelpLinks/AllItems.aspx
Then select the List named HelpLinks in the sub site Help. Dev will be the top most node(site). Help will be a sub site and inside Help you can find List by name HelpLinks .
All the links in the page and their title will be displayed
Select the title of link which you want to open in new tab and right click.
Select Edit properties. Then in the URL field and call the function as javascript:load_url(‘http://www.google.co.in’); instead of http:// www.google.co.in
Or Else Suppose you want to change the links in the below URL. URL: http:// someserver/sites/Dev/Help/HelpLinks/AllItems.aspx
open to the link http:// someserver/sites/Dev/Help/HelpLinks/AllItems.aspx
You will find the columns of the List (Title Column, URL column, Summary etc).
Select the Title and click Edit property which you want to edit