FFan丶Blog / 部分JS效果 / / 一些JS小技巧

一些JS小技巧

分类:部分JS效果 发布时间:2022-08-15 09:25:10来源:FFan丶Blog
屏蔽 IE 浏览器 //Kill XP and IE8 (function() {     var ua = navigator.userAgent;     var res = /Windows NT (\\d+\\.\\d+)/.exec(ua);     var xpOrLower = res && JSON.parse(res[1]) < 6;...

屏蔽 IE 浏览器

//Kill XP and IE8

(function() {

    var ua = navigator.userAgent;

    var res = /Windows NT (\d+\.\d+)/.exec(ua);

    var xpOrLower = res && JSON.parse(res[1]) < 6;

    res = /MSIE (\d+\.\d+)/.exec(ua);

    var ie8OrLower = res && JSON.parse(res[1]) < 9;

    if (xpOrLower || ie8OrLower) {

        alert("请不要用XP及之前的Windows系统,和IE8及之前的IE浏览器访问本站!");

        location.href = "about:blank";

    }

})();


屏蔽百度搜索

var fromBaiduSE = /^https?:\/\/www.baidu.com/.test(document.referrer);

if (fromBaiduSE) {

    alert("检测到你还在使用百度搜索,作为一个程序员,这是一种自暴自弃!\n\n做不作恶的程序员,从不用百度开始!")

    location.href = "about:blank";

}


防盗链

如果是视频、图片等静态资源的防盗链,通过服务器判断 referer 即可阻止非法访问。而要防止自己的页面被其他网站用作 <iframe>,则可以通过以下 JavaScript 代码来实现:

if (top.location != self.location) top.location = self.location;

if (document.location.search.match(/type=embed/gi)) {

    window.parent.postMessage("resize", "*");

}


禁止选中复制

监听 onselectstart 事件,即可阻止用户的拖拽选择行为:

document.onselectstart = function(event) {

    event.preventDefault();

    return false;

}


猜你喜欢

  • 快速把excel合并在一起,方便分析和统计可以利用excel表的宏计算就可以实现。方法如下: 1、我们需要把多个excel表都放在同一个文件夹里面,并在这个文件夹里面新建一个excel。

    其他2020-01-15
  • Copyright &#169; <script>var d=new Date();document.write(d.getFullYear());</script> FFan. All rights reserved.

    部分JS效果2020-01-15
  • 四边为虚线边框:border:1px dashed #000; 左边为虚线:border-left:1px dashed #000; 右边为虚线:border-right:1px dashed #000; 顶部边(上边)为虚线:border-top:1px dashed #000; 底部边(下边)为虚线:border-bottom:1px dashed #000;

    CSS2020-01-15
  • 1、四个边框 border-left 设置左边框,一般单独设置左边框样式使用border-right 设置右边框,一般单独设置右边框样式使用border-top 设置上边框,一般单独设置上边框样式使用border-bottom 设置下边框,一般单独设置下边框样式使用,有时可将下边框样式作为css下划线效果应用。

    CSS2020-01-15
  • /*用CSS控制将li标签竖排变横排*/ display: inline-block; /*内边距*/ padding /*外边距*/ margin

    CSS2020-01-15