簡體   English   中英

在新窗口中打開所有外部鏈接

[英]Open all external links in new window

我正在使用下面的代碼來隱瞞所有通過php腳本傳遞的鏈接-現在我希望這些鏈接在新窗口中彈出

 $( document ).ready(function() {  
$("a[href^='http']").each(function() {
 var value = $(this).attr('href');
 $(this).attr('href','<url>/pqr.php?'+value);
});

});

鏈接是否在同一窗口中打開? 如何在新窗口中打開它們。

如何添加這個:

$(this).attr("target","_blank");

編輯:像這樣集成:

$( document ).ready(function() {  
    $("a[href^='http']").each(function() {
        var value = $(this).attr('href');
        $(this).attr('href','<url>/pqr.php?'+value);
        $(this).attr("target","_blank");
    });
});

為我工作: http : //jsfiddle.net/bontp6jk/

這個怎么樣

$(document).ready(function(){
$("a").attr("target","_blank");

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM