Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #753

    Hi,

    How can I make it so that any and all External Links out of the website will open in new windows, without having to use target and blank for each one?

    It would be great to do it without a plugin.

    Thanks!

    #32766

    In custom.js replace

    jQuery.noConflict();

    jQuery(document).ready(function(){

    with

    jQuery.noConflict();

    jQuery(document).ready(function(){

    jQuery(function(){jQuery('a[href][rel*=external]').each(function(i){this.target = "_blank";});});

    now instead of target=”_blank” you can write rel=”external” and the javascript will add target=”_blank”. The advantage is that your site will be w3c valid.

    Example:

    <a href="your-external-site.com" rel="external">Your Link</a>

    The Dude

    #32767

    Hi,

    Thank you for your help, and please forgive my lack of understanding…

    If I replace the code, do you mean that for each link I still have to type in re=”external”?

    If yes, I was hoping to avoid that. In other words, whatever external link I was to add or would be on the site would automatically just open a new window.

    Is that possible, and how?

    Thanks so much!

    #32768

    Yes you could use following code to achieve this:

    jQuery("a[href^='http:']").not("[href*='mydomain.com']").attr('target','_blank');

    The Dude

    #32769

    Disregard

    #32770

    Hi,

    I forgot about this!

    For: jQuery(“a[href^='http:']“).not(“[href*='mydomain.com']“).attr(‘target’,’_blank’);

    Where do I insert this code, and do I have to remove something else for this code?

    Thanks so much and please forgive my lack of knowledge!

    #32771

    In custom.js replace

    jQuery.noConflict();

    jQuery(document).ready(function(){

    with

    jQuery.noConflict();

    jQuery(document).ready(function(){

    jQuery("a[href^='http:']").not("[href*='mydomain.com']").attr('target','_blank');

    The Dude

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘How to Open all External Links in new windows?’ is closed to new replies.