2

ユーザーが自分のサイトの外部リンク (特定の ID またはクラスのいずれかで識別される) をクリックすると、10 秒のカウンターでポップアップが表示され、10 秒後にポップアップが閉じ、ユーザーができるようになります。外部 URL にアクセスします。これはどのように行うことができますか?以下のような警告を表示できますが、タイムアウトを追加する方法がわかりません。また、これはボックスであり、カウンターが停止するまでユーザーが表示できるものをconfirm追加できるポップアップではありません。div

$(document).ready(function(){

var root = new RegExp(location.host);

$('a').each(function(){

    if(root.test($(this).attr('href'))){ 
        $(this).addClass('local');
    }
    else{
        // a link that does not contain the current host
        var url = $(this).attr('href');
        if(url.length > 1)
        {
            $(this).addClass('external');
        }
    }
});

$('a.external').live('click', function(e){

    e.preventDefault();
    var answer = confirm("You are about to leave the website and view the content of an external website. We cannot be held responsible for the content of external websites.");

    if (answer){
        window.location = $(this).attr('href');
    } 

});

});

PS: 無料のプラグインはありますか?

4

3 に答える 3

1

alert()がすべてのスクリプトの実行をブロックしているため、この種のダイアログとしてネイティブ確認ダイアログ ボックスを使用することはできません。カスタマイズされたダイアログ ボックスのノンブロッキングを使用する必要があります。

たとえば、jquery UI ダイアログを使用できます。

これにはモーダル オプションがありますが、これは UI のブロックではありません。

于 2013-06-01T14:41:19.037 に答える
0

setTimeout特定の遅延の後にアクションを実行するためにJavaScript関数を使用するConsdier

if (answer){
    setTimeOut(function(){
       //action executed after the delay
       window.location = $(this).attr('href');
    }, 10000); //delay in ms

}
于 2013-06-01T14:31:07.470 に答える