January 2, 2014

Weebly Tricks #1 - Open All external Links in a New Tab

Posted by Domingo Tambasacan at 1/02/2014

Automatic open all links in a new tab


Credits to mybloggertricks.com for we will be using their code and we will apply it to your Weebly site. This code was designed to make all external links open in a new tab including images. I tried it myself on my Weebly site and it works perfectly.This method is very useful in saving time making links opens automatically instead of manually clicking the "Open in a new Window" check box.




Now lets begin:

1. Go to your Weebly site > Design

2. From the lower left part click: Edit HTML/ CSS

3. Now from the left corner you can see the list of available Page Lay Outs

4. Click on the first one which is tall-header.html

5. Look for </head>. (just press ctrl F to find)

6. Above the </head> paste the following codes:

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

<script type='text/javascript'>

$(document).ready(function() {

  $("a[href^='http://']").each(
    function(){
     if(this.href.indexOf(location.hostname) == -1) {
        $(this).attr('target', '_blank');
      }
    }
  );
$("a[href^='https://']").each(
function(){
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr('target', '_blank');
}
}
);


});

</script>

7. Simply save the template and check your links.

8. If you want to apply it on the whole site or specified page lay out or in selected pages read the article for editing head.

NOTE:

1. This code works on images too!

2. You can simply override this code if you manually tick the "open in a new window" option even the link is your own domain name.

3. If you change your domain name specially if you bought a new domain and use it to replace your sub domain, you must remove the code first then publish and then insert the code again. If you won't do it then all your links before you changed your domain name will open in a new tab.

This is my first post here in my site and hopefully it helps you.

Get email updates and more access! (Free)
Email *
email marketing by activecampaign

About Author:

Hi I am Domz. I love inserting new widgets and effects on Weebly Template. I like helping people and I like them more being my subscriber. Follow me @ Twitter | Facebook



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!

...

0 comments:

Have any question? Feel Free To Post Below:

 

© 2014. All Rights Reserved | My Weebly Tricks | Template by Blogger Widgets

Home | | Privacy Policy | Top