我希望当用户点击我网站上的任何外部链接(由特定 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:有没有免费的插件呢?