javascript - Using jQuery to open all external links in a new window - Stack Overflow

New to jQuery here.I've found several web pages that e close to what I'm trying to do, but

New to jQuery here. I've found several web pages that e close to what I'm trying to do, but not quite. Actually, I think the following is supposed to actually work, but it's saying:

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

is not recognized (syntax error). Any help?

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

Thanks.

New to jQuery here. I've found several web pages that e close to what I'm trying to do, but not quite. Actually, I think the following is supposed to actually work, but it's saying:

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

is not recognized (syntax error). Any help?

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

Thanks.

Share Improve this question edited Dec 9, 2009 at 3:24 Justin Johnson 31.3k7 gold badges66 silver badges89 bronze badges asked Dec 9, 2009 at 3:14 Jeff LambJeff Lamb 5,8754 gold badges39 silver badges57 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

No need for the @ symbol. Other than that, you're golden.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744375623a4571171.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信