jQuery1.7~1.8 で外部リンクを自動別窓オープン

jQueryのバージョンを上げるごとに動かなくなるのってなんだかなぁ、と。結局は若干重そうに見えても簡単・基本的なコードで仕上げるほうが手間取られなくていいと思う今日この頃です。

/*
 * DESC: Another location link use target _blank.
 * UPDATE: (2012-08-17)
 * AUTHER: Luvsic
 * LISENCE: MIT
 * INFO: http://luvsic.net/item/150
 *
 */


jQuery(function(){

        var mysite = location.hostname;
        $('a[href^=http]')
                        .not('[href*="'+mysite+'"]')
                        .addClass('external')
                        .attr('target','_blank');

});
Skooler Records

No comments yet

%3c%69%6e%70%75%74%20%74%79%70%65%3d%22%68%69%64%64%65%6e%22%20%6e%61%6d%65%3d%22%6e%70%5f%70%72%6f%74%65%63%74%62%79%6d%64%35%22%20%76%61%6c%75%65%3d%22%61%65%36%33%36%33%37%30%38%30%39%39%36%35%64%36%36%64%62%37%66%34%66%30%33%34%37%34%33%62%38%39%22%3e %3c%69%6e%70%75%74%20%74%79%70%65%3d%22%68%69%64%64%65%6e%22%20%6e%61%6d%65%3d%22%6e%70%5f%70%72%6f%74%65%63%74%62%79%6d%64%35%5f%68%61%73%68%22%20%76%61%6c%75%65%3d%22%36%32%39%61%64%35%65%39%34%66%31%35%37%35%35%38%31%36%62%37%61%66%33%31%30%66%31%62%62%36%64%31%22%3e
© 2006 – 2014 by Luvsic. Some rights reserved.