繁体   English   中英

使用jQuery在新窗口中打开所有外部链接

[英]Using jQuery to open all external links in a new window

这里是jQuery的新手。 我发现几个网页接近我正在尝试做的事情,但并不完全。 实际上,我认为以下内容应该可行,但是它说:

[@href^="http://"]

无法识别(语法错误)。 有帮助吗?

$(document).ready(function() {
    $('a[@href^="http://"]').filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    }).attr('target', '_blank');  
});

谢谢。

不需要@符号。 除此之外,你是金色的。

$("a[href^='http://']")...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM