简介
使用全局javascript代码,使 即将离开网站到别的页面时候跳转到专属的提示离开页面,或者跳转到弹窗页面
功能代码
<script type="text/javascript">
$("a:not([href*='javascript:'])").click(function(e){
let leaver_url = "{:getCategory(54, 'url')}";
// 禁止A默认跳转
e.preventDefault();
// 当前页面HOST链接
if ($(this).attr('href')) {
var winhref = window.location.host;
// 获取点击的A标签域名
var ahref = $(this).attr("href");
var atarg = $(this).attr("target");
// 判断是否当前博主的旗下网页
if (ahref.indexOf("://") != -1) {
if(ahref.indexOf(winhref) < 0){
// 不同
if(atarg == "_blank"){
window.location.href = leaver_url+"?url="+ahref+"&target=_blank";
}else{
window.location.href = leaver_url+"?url="+ahref+"&target=_self";
}
}else{
if(atarg == "_blank"){
window.open(ahref);
}else{
window.location.href = ahref;
}
}
}else{
if(atarg == "_blank"){
window.open(ahref);
}else{
window.location.href = ahref;
}
}
}
})
</script>
页面代码
{block name="banner"}
<style type="text/css">
html,body{background:#F3F4F5;padding:0;margin:0;}
.content{padding-top:220px;width:450px;margin:auto;word-break: break-all;}
.content .logo-img img{display: block;width:275px;height:auto;margin:auto;margin-bottom: 16px;}
.content .loading-item{background:#fff;padding:24px;border-radius: 12px;border: 1px solid #E1E1E1;}
.content .flex{display:flex;align-items:center;}
.content .flex-end{display:flex;justify-content:flex-end;align-items: center;}
.content .loading-activity {display: block;width: 100%;overflow: hidden;text-overflow: ellipsis;color: #4049f0;font-size: 14px;}
.content .tip1{background:#F0F9EA;}
.content .tip2{background:#FDF5E6;}
.content .tip3{background:#FEF0F0;}
.content .loading-color1{color:#267DCC;}
.content .loading-color2{color:#FC5531;}
.content .loading-tip{padding:12px;margin-bottom:16px;border-radius:4px;}
.content .loading-topic{font-size: 14px;color: #222226;line-height: 24px;margin-bottom:24px;}
.content .loading-img{width:24px;height:24px;}
.content .loading-btn{white-space: nowrap;font-size: 14px;color: #FC5531;border: 1px solid #FC5531;display:inline-block;box-sizing: border-box;padding:6px 18px;border-radius: 18px;margin-left:8px;cursor: pointer;}
.content .loading-btn-github{width:121px;background:#FC5531;color:#fff;}
.content .loading-text{font-size: 16px;font-weight: 600;color: #222226;line-height: 22px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;}
.codyUrl{padding: 4px 10px;background: #000;border-radius: 4px;position: fixed;top: 20px;left: 50%;transform: translateX(-50%);color: #fff;font-size: 14px;display: none;}
#adCody{width: 110px;font-size: 14px;color: #CCCCD8;cursor: pointer;}
#adCody:hover{
text-decoration: underline;
}
@media (max-width: 450px){
.content{padding-top:120px;width:94%;}
}
#csdn-toolbar{width: 0;height: 0;display: none}
</style>
{/block}
{block name="header"} {/block}
{block name="main"}
<div class="targ content">
<a class="logo-img">
<img {:explodeImgTit($getpageinfo['logo'], $SEO['site_title'])} />
</a>
<div class="loading-item loading-others">
<div class="flex loading-tip tip2">
<div class="loading-text">{$getpageinfo['remind']}</div>
</div>
<div class="loading-topic">
{php}
$leave_url = $param['url'] ? $param['url'] : $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST']."/";
$leave_target = $param['target'] ? " target='".$param['target']."' " : " target='_self' ";
$leave = str_replace("[url]",'</span><a class="loading-color2" href="'.$leave_url.'" '.$leave_target.'>'.$leave_url.'</a><span>', $getpageinfo['leave']);
{/php}
{$leave|raw}
</div>
<div class="flex-end">
<a class="loading-btn" href="{$leave_url}" {$leave_target}>{$getpageinfo['btn']}</a>
</div>
</div>
</div>
{/block}
版权声明:本文为原创文章,版权归 星环博客 所有,转载请注明出处!
本文链接: https://xhto.cn/archives/277.html
友情提示:添加友联和友联失效404的请联系博主,并确保自己网站已经添加博主为友联!
黑色的背后是黎明... + 赞赏博主吧!已经穷的开不起站了~
文章的确不错啊https://www.cscnn.com/
想想你的文章写的特别好https://www.237fa.com/