Follow us on Facebook

Open All External Links in New Window or New Tab Automatically with Java

Earlier we discussed how to make external links nofollow automaticallyhowever there are many things to keep in mind when you are writing a good blog post. Another useful way for smart blogging is adding target="_blank" attribute to all external links. This will let your blog open an an external link in new tab or new window. Web browsers also have an option to open any link in new tab or new window however most of the internet users will click the link directly and this will take your blog reader away from your blog. So, try adding this attribute to every external link.

How to Open External Links in New Window?

You do this either manually or automatically. If you are willing to do this manually, simply add the highlighted code in your hyperlink.
<a href="" target="_blank">
However, adding this code to all external links can be time consuming so its always good to let a script do it for you automatically. Here is a JavaScript which will make all external links to open in a new tab or new window.

Open External Links in New Tab Automatically

  • If you're using, Login Your blogger account, Go to Dashboard > Design > Edit HTML (if you are using any other platform, simply move to next step)
  • Search for </body> in your template (tip: press Control and F key at once and paste this code)
  • Paste this JavaScript code just Before searched code.
<script src='' type='text/javascript'/>
<script type='text/javascript'>
jQuery('a').each(function() {
// Let's make external links open in a new window.
var href = jQuery(this).attr('href');
if (typeof href != 'undefined' && href != "" &&
(href.indexOf('http://') != -1 || href.indexOf('https://') != -1) &&
href.indexOf(window.location.hostname) == -1) {
jQuery(this).attr("target", "_blank");
  • That's it... Now all external links in your blog will open in new tab.

Moreover, there is little difference in _new and _blank.  For example, if a link has _blank attribute and you click on the link 10 times, 10 new tabs will open the same link. However if a link has _newattribute and you click on the link 10 times, link will appear in 1 window and the same page will be refreshed 9 times. So, you can alter this attribute from above given JavaScript according your need.

No comments:

Post a Comment



Like Us


Donate us For Furture