开发者

How to prevent this code from affecting img onclick?

开发者 https://www.devze.com 2023-01-15 10:32 出处:网络
$(document).ready(function(){ $(\"a[href*=\'http://\']:not([href*=\'开发者_运维技巧\"+location.hostname+\"\'])\").attr(\"target\",\"_blank\");
$(document).ready(function(){


$("a[href*='http://']:not([href*='开发者_运维技巧"+location.hostname+"'])").attr("target","_blank");

$("a[target!='_blank'][target!='_top']").live('click', function(){
$("#actualcontent").html('<center><img src="/deltasite/uploads/smallloader.gif"></center>');

var url=$(this).attr("href")+'?jquery=1';

$("#actualcontent").load(url);


$("#nav").load('/delta/pack_files/other/nav.php?url=' +$(this).attr("href"));

window.location.hash=$(this).attr("href");
        return false;  
    });

});

For some reason, on one embedded page of the site, this seems to affect links and images with onclick attribute. Any idea why? (Even if their target is blank or top). It only seems to do it on one page, annoyingly.

Any ideas?

Thanks, Tom.


Try excluding images/links which have an onclick attribute, using a combination of the :not selector and the has attribute selector:

$("a[href*='http://']:not([href='foo']):not([onclick])").attr("target","_blank");

Demo: http://jsfiddle.net/HjYEX/2/

0

精彩评论

暂无评论...
验证码 换一张
取 消