切换到宽版
  • 704阅读
  • 1回复

【主题美化&增强系列】Jquery式的JS进行外链判断 [复制链接]

上一主题 下一主题
 

只看楼主 倒序阅读 使用道具 0楼 发表于: 2010-10-03
— 本帖被 ralix 设置为精华(2010-10-03) —
效果


原理——超级简单
1.append进行传输
2.indexOf进行判断

记得加载Jquery

JS代码——English
  1. $('a:not(.nboxla)').click(function(){
  2. var URLnow = document.location.href.match(/^(http:\/\/)?([^\/]+)/i);
  3. var nBoxURL = URLnow[2];
  4.     if(this.href.length>0&this.href.indexOf('javascript')<0){
  5.         if(this.href.indexOf(nBoxURL)<0)
  6.         {this.nBoxHref = this.href;
  7.         this.nBoxHref = (this.nBoxHref.length>35?this.nBoxHref.toString().substring(0,35)+"...":this.nBoxHref);
  8.         var nBox = '<div id="nbox"></div><div class="nbox"><h4>Warning</h4>U are going to visit an OUTSIDE website,<br />Are u Sure?<br />URL: '+this.nBoxHref+'<br /><p><a id="nboxcontinue" href="'+this.href+'" target="_blank">Continue</a><a id="nboxcancel">Cancel</a></p><br /></div><script type="text/javascript">$("#nboxcancel, #nbox").click(function(){$("#nbox, .nbox").remove();});$("#nboxcontinue").click(function(){$(this).text("Risk Urself");window.open = $(this).attr("href");});</script>';
  9.             $('body').append(nBox);
  10.             return false;}
  11.         }
  12.     });


JS代码——中文
  1. $('a:not(.nboxla)').click(function(){
  2.     var URLnow = document.location.href.match(/^(http:\/\/)?([^\/]+)/i);
  3.     var nBoxURL = URLnow[2];
  4.         if(this.href.length>0&this.href.indexOf('javascript')<0){
  5.             if(this.href.indexOf(nBoxURL)<0)
  6.             {this.nBoxHref = this.href;
  7.             this.nBoxHref = (this.nBoxHref.length>35?this.nBoxHref.toString().substring(0,35)+"...":this.nBoxHref);
  8.             var nBox = '<div id="nbox"></div><div class="nbox"><h4>警告</h4>您将要访问的链接非本站内部链接,<br />确定访问?<br />地址: '+this.nBoxHref+'<br /><p><a id="nboxcontinue" href="'+this.href+'" target="_blank">继续</a><a id="nboxcancel">取消</a></p><br /></div><script type="text/javascript">$("#nboxcancel,#nbox").click(function(){$("#nbox,.nbox").remove();});$("#nboxcontinue").click(function(){$(this).text("请自行承担后果");window.open = $(this).attr("href");});</script>';
  9.             $('body').append(nBox);
  10.             return false;}
  11.         }
  12.     });


CSS美化
  1. #nbox{ /*此tag作用为整体覆盖*/
  2.     z-index:998; /*层显示为998*/
  3.     position:fixed; /*固定*/
  4.     top:0; /*距上方*/
  5.     left:0; /*距左方*/
  6.     height:100%; /*高度百分百,即占整个浏览器页面的100%,全覆盖*/
  7.     width:100%; /*宽度百分百,同上*/
  8.     background:url(images/nbox.png); /*此为透明图片*/
  9. }
  10. .nbox{ /*此tag作用为包裹内容,使其整体居中*/
  11.     font:110%/135% 'Comic Sans MS',Georgia, 'Times New Roman', Times, serif; /*字体,请自定义*/
  12.     text-shadow:#ccc 1px 1px 1px; /*在Chrome与FF下非常友好的文字阴影*/
  13.     z-index:999; /*层显示为999,即为最上层*/
  14.     margin:0 auto; /*左右居中*/
  15.     width:300px; /*宽度*/
  16.     height:150px; /*高度*/
  17.     position:fixed; /*固定*/
  18.     top:50%; /*浏览器50%的位置*/
  19.     left:50%; /*同上*/
  20.     margin:-75px 0 0 -150px; /*对位置进行修整,使其中点与浏览器中心重合 顺序为上右下左*/
  21.     background:#e5eff1; /*背景色*/
  22.     border:3px #eff solid; /*边框颜色*/
  23.     padding:5px;
  24. }
  25. .nbox h4,.nbox p{ /*此tag作用为标题以及内容*/
  26.     width:100%; /*宽度百分百*/
  27.     padding:10px 0;
  28.     text-align:center; /*居中*/
  29. }
  30. .nbox a{
  31.     cursor:pointer;
  32.     padding:5px 20px;
  33. }
  34. .nbox a:hover{
  35.     background:#fcf7bd;
  36. }


所要用到的素材(记得放到主题文件夹的images文件夹里)


本文整理自 WORDPRESS BOX

只看该作者 1楼 发表于: 2010-10-03
这个也挺有用的~
快速回复
限100 字节
 
上一个 下一个