--> Stop all Internal Links From Opening In New Window | Experience Lab - Online business creation and development guide for bloggers and startups

Stop all Internal Links From Opening In New Window

In 2013 we shared a script snippet that helped you to automatically open all external links in a new browser window . That script received g...

Open links in new window in blogger and wordpressIn 2013 we shared a script snippet that helped you to automatically open all external links in a new browser window. That script received great feedback and we thought to further enhance it. Today's jquery script will prevent internal links containing the attribute target="_blank" from opening in a new tab. It will open all links inside a new window except internal links. This plugin will look for all http and https hyperlinks inside your blog content section which includes the blog post body and comment body. It will then add a target="_blank" attribute to all external links but will remove target="_blank" attribute from all internal links found inside your blog post and comments.

The target attribute inside <a> tag was never meant for internal links at all and therefore it makes no sense to irritate your website visitors by opening blog links inside new tabs thus forcing them to close the previous page in order to read the current page in new tab. The tutorial below includes instructions for both blogspot blogs and wordpress blogs. This script will immensely improve your daily pageviews and will tremendously decrease the overall blog bounce rate thus leading to a better search engine ranking and of course blog revenue.  We have implemented it on mbt and also on our wordpress blog and it is working just great Alhamdulillah.

Open all links In New Tab Except Internal Links

Blogger templates and Wordpress themes have different DOM structures and therefore due to the difference in class and ID name, I will be discussing the installation steps separately for both platforms.

FOR BLOGGER

1 Go To Blogger > Template

2 Backup your template

3 Click Edit HTML

4 Paste the following script just above </head> tag.

<script async='true' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>

<script type='text/javascript'>
//<![CDATA[
//Open External Links in New Window - Plugin by STCnetwork.org
$(document).ready(function(){
$("#Blog1 a[href^=http], #Blog1 a[href^=https]")
  .each(function(){
    if (this.href.indexOf(location.hostname) == -1){
      $(this).attr({ "target":"_blank" })}
    if (this.href.indexOf(location.hostname) != -1){
    if ( $(this).attr('target') == '_blank')  {$(this).attr("target", "");}}
  });});

//]]>
</script>

Note: Remove the yellow highlighted code if you already have added jQuery library inside your template

5 Save your template and all done!

FOR WORDPRESS

Follow these steps for a wordpress blog to open external links in a new window but open internal links inside the same window.

1 Go to your theme settings page or go to Appearance > Editor > header.php

2 Paste the following code just above </head> tag.

<script async='true' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>

<script type='text/javascript'>
//<![CDATA[
//Open External Links in New Window - Plugin by STCnetwork.org
$(document).ready(function(){
$("#content a[href^=http], #content a[href^=https]")
.each(function(){
if (this.href.indexOf(location.hostname) == -1){
$(this).attr({ "target":"_blank" })}
if (this.href.indexOf(location.hostname) != -1){
if ( $(this).attr('target') == '_blank') {$(this).attr("target", "");}}
});});

//]]>
</script>

Note: Remove the yellow highlighted code if you already have added jQuery library inside your template

3 Save  Settings and you are all done!

How are Internal and external links Identified?

The script looks for all links inside the post body and comment body. It then removes target attribute from all internal links and adds it in external links only. The location.hostname variable checks if the link is an internal link or external. For external links the condition is set to ==-1 and for internal links the condition is set to !=-1

If you are using my old script, I will recommend that you replace it with this new script which is much more lightweight and SEO friendly..

I hope these new script may put a positive effect on your overall page impressions and help you engage readers more on your site instead of irritating them with popping links in new tabs. Let me know if you need any help. =)

COMMENTS

Name

Affiliate Marketing,12,Announcement,34,Bing,9,Bitcoin,38,blog,7,Blogger Resources,42,Blogger Templates,4,blogger tricks,156,Blogging ethics,70,Blogging tips,198,Bugs and Errors,34,Business,9,Copyright Violation,9,CSS and HTMLTricks,95,Designs,8,drop down menu,7,eBook,12,Email Marketing,7,Events,30,Facebook,30,Facebook tricks,49,Google,157,Google AdSense,42,Google Analytics,7,Google Plus,51,Google Plus Tricks,38,Guest Posts,112,home,2,How To,77,Internet,1,JSON Feeds,25,Kitchen Recipes,2,Label Based Sitemap Themes,1,Make Money Online,108,Marketing,16,MBT Blogger Templates,7,Menus,1,News,146,Pages,1,Posts,10,presentations,15,Responsive,10,Reviews,7,SEO,307,Settings,6,Shortcode,15,Sitemap Themes,1,Social Media,155,Technology,7,Templates,1,Tips,2,Tools,1,Traffic Tips,80,Video,19,Web Designing,62,web hosting,18,Webmaster Tools,97,Widgets,199,wordpress,26,
ltr
item
Experience Lab - Online business creation and development guide for bloggers and startups: Stop all Internal Links From Opening In New Window
Stop all Internal Links From Opening In New Window
https://lh3.googleusercontent.com/-6lvyw3DAbq0/VpOZ1-KoAMI/AAAAAAAAQF0/32l-jeTLBek/image%25255B25%25255D.png?imgmax=800
https://lh3.googleusercontent.com/-6lvyw3DAbq0/VpOZ1-KoAMI/AAAAAAAAQF0/32l-jeTLBek/s72-c/image%25255B25%25255D.png?imgmax=800
Experience Lab - Online business creation and development guide for bloggers and startups
https://www.experiencelab.info/2016/01/stop-all-internal-links-from-opening-in.html
https://www.experiencelab.info/
https://www.experiencelab.info/
https://www.experiencelab.info/2016/01/stop-all-internal-links-from-opening-in.html
true
2959477579779989044
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy