我正在使用此脚本强制使用Jquery在新窗口中打开到Open的链接,并且工作正常
// add external links
function addExternalLinks () {
$("a[href*='http://']:not([href*='"+location.hostname.replace
("www.","")+"']), a.linkException").each(function() {
if($(this).find('img ').length == 0) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
}).addClass('externalLink').attr("title", $(this).attr("title")+" - ( This link will open in a new window )");
}
});
}
但是,页面的一部分正在使用通过LOAD从外部HTML页面加载的内容。
function showInfo( info ) {
$("#layerinfo").load("descriptions.html #" + info );
};
我希望包含在此已加载内容中的链接也被强制在具有相同脚本的新寡妇中打开。我无法使其正常工作。
就像是 :-
function showInfo( info ) {
var infoContent = "descriptions.html #" + info;
$("#layerinfo").load(infoContent,function(){
$("#layerinfo").html().addExternalLinks();
});
};
任何帮助,不胜感激。
addExternalLinks
只是一个函数,而不是String的方法(.html
返回的结果),也不是要链接的jQuery方法。
$("#layerinfo").load(infoContent, function () {
addExternalLinks();
});
顺便说一句,addExternalLinks
您不能只添加.attr("target", "_blank")
到上述链接而不是使用click事件吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句