屏蔽 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;

}


支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

版权声明:若无特殊注明,本文皆为( FFan )原创,转载请保留文章出处。