How to Open Links in New Windows for Bloggers

  • by
If you would like to make every link in post opened in new windows, you don't have to add target="_blank" in every <a> tag, you can just add a jQuery script code snippet under <head> tag. Here are the steps:
  1. Edit the blog template.
  2. Edit the blog template
  3. Find <head>, and add a block of jQuery codes under <head>, and Save template.
  4. Add a block of jQuery code into the blog template
    The added jQuery codes are as below:
      <head>
        <script src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'/>
        <script type='text/javascript'>
          $(document).ready(function() {
             $('.post-body a').attr('target', '_blank');
          });
        </script>

        ...
      <head>

    In the jQuery codes, I did not select all <a> tags in this blog to be opened in new windows, I only selected with $('.post-body a'), which means I selected <a> tags only inside post-body. Of course, you can replace the outer class or id of the element with the one you designated. It's very useful when you want to confine the scope of this feature.

Leave a Reply

Your email address will not be published. Required fields are marked *