簡體   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