How to open anchor tag links in a new window?
In this article, I am going to explain you how to open the anchor tag links to get opened in a new window. I will explain you the different ways to open the anchor tags in a new window. I will explain how important this method is for the bloggers and content writers.
This article gonna be an interesting one for all web surfers. Almost everyone who browses through the content on the web comes across many links in between the content, in which most of them redirects to its respective page.This makes the user to lose his continuity to read the actual page sometimes as it would be disgusting for the reader to always come back to the actual page whenever he click through a link.This may annoy the reader and may stop him reading the article further.
In order to overcome such simple activities which might annoy the reader, we can best do is to just open the anchor tags i.e. the links in a new window. Opening the links in a new window will help the reader to just go through the opened window as well refer to the actual content page in parallel. This helps the reader not to lose the link with the actual page.Ways to open anchor tags in a new window:
We can do this in two ways,
1. One way is letting all the anchor links to get opened in a new window.
2. Other one is letting the anchor links present in a specified area of the page to get opened in a new window.
In order to achieve the first idea, our basic HTML can do it for us.
Just add the following in the head section of your HTML.<base target='_blank' />
This serves your first idea pretty well, but think once whether it helps you all the times. I say no because, in many pages we create layouts which contain tabs and links which are meant to show some content within the same page of our site ,these are the links which are not actually meant to open in a new window.
If we make user to open each and every tab of your navigation bar opened in a new window, this idea goes even worst.
So the first idea doesn't look fair for a common web page which have tabs ad links in the navigation bar.
So our next idea is to open the anchor links of a particular section of the page in a new window.
Say I am on my blog home page and I have a section where I display my content in a div tag with id='my-Content'. I am using some anchor links in my div section. So the idea to implement this is I should allow only the links present in my div section to get opened in a new window.
This could be done using a simple JavaScript event.
Place this script in your head section of your HTML page.
<script type='text/javascript'>
window.onload = function () {
var links = document.getElementById('my-Content').getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
links[i].setAttribute('target', '_blank');
}
}
</script>
I you like to implement with jQuery then use this
$('#my-Content a[href^="http://"]').attr("target", "_blank");
That's all , these few lines do the trick for you ,So i hope you all are now aware of how to open anchor tag links in a new window
The chief beneficiaries of this trick are the bloggers since they need to use more links to support their content and at the same making the reader not to leave their page.
Write your anchor tag as usual:Opening Anchor tag element's hyperlinks in new window or new tab of applications programme may be a technique of HTML. In different words, net links among an internet page will be opened in new window or tab of visitor's browser by inserting an HTML attribute in anchor tag code and it's referred to as target attribute. This HTML attribute is generally employed in gap external websites in either new window or tab of applications programme however not recommendable for gap internal websites in net browser's new tab or window.
Target blank AttributeThe actual reason of inserting this HTML attribute in anchor tag is to permit guests to come back back to our article once reader completes reading external net page's content. If website owner didn't embrace this attribute in anchor tag code, applications programme opens external links in same window of article whenever website traveler clicks on different site's web content link during a electronic computer. Similarly, traveler might not return to your site's article however starts surfboarding on different web site (external link's site) to be told additional data.
Therefore inserting target="_blank" HTML attribute in anchor text tag's code in your website's articles for external websites is recommendable and it helps guests to envision your site's article once more whenever your site traveler closes external net page's window or tab of browser.
a href=""
Add the attribute target="_blank":
a href="" target="_blank"
Write your link text, and close your link tag:
link text /a
Tips:
There are several specific targets: _top, _parent, _blank, _self
You can also target a new window with a name: target="any name here"
Named windows can be referenced by other links as well, so they all open in the one window
What You Need
HTML Editor -or-
Text Editor