Set all LibGuides hyperlinks to open in a new window

Use this jQuery in your LibGuides Custom JSS/CSS window to add the target attribute of “_blank” to all anchor elements inside LibGuides’ page content boxes which do not already have a target attribute specified.

LibGuides offers a way to set the default behavior for all LibGuides ‘Link’ objects site-wide, such that when clicked they open in a new window or tab. To set this option:

Click Admin (menu) > System Settings (submenu) > General (tab) > Guide Options (accordion) and set Window Target to ‘New Window’.

However, this setting applies only to the LINK content type (the link type added from the ‘Add/Reorder’ dropdown).

The problem is, we most commonly want our LibGuides to persist (stay open) as a launching page, so to say, for all the cool links with which we fill our LibGuides. The setting above does not apply to all the inline links you create in regular paragraphs inside the rich-text editor and you must explicitly change the default target attribute to “New Window (_blank)” for each ‘regular’ link you add to the page.

Thankfully, changing this default is easy with a little jQuery. This can be added to the custom CSS/JS box for an individual guide or the whole site.*

<script type="text/javascript">

     $('.s-lib-box-content a:not([target])').attr("target","_blank");


* Be careful when working in the Custom CSS/JS windows. Certain syntax errors can cause the Blue Screen of Death and lock up your guide!

After adding this code, all links which do not already have their target attribute set will be set to target="_blank" and open in a new window or tab automatically. If you now wish to have a link load in the same window, you will need to set this manually. You can do this in two ways.

  1. Add target="_self" to your link in the code window.
    <p>See our <a href="help.pdf" target="_self">Help Document</a> for more information.</p>>
  2. Selecting “Same Window (_self)” from Target dropdown in the Target tab in the Link box.
Share Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrEmail this to someone