网站首页
免费技术
源码下载
免费软件
域名空间
活动资讯
值得一看
关于本站
网址导航
您的位置:首页 > JS网页代码 > 简单通过JS实现网站授权
简单通过JS实现网站授权
2021-7-19    1176    0

JS如何给网页添加版权验证?通过Js判断当前页面的URL是否是授权的域名,如果是授权的域名,就正常加载,如果不是授权的域名就弹出授权提示。
首先需要在网站页头添加:
<script src="xhsq.js"></script>
在修改JS文件,第15行替换域名即可!
document.onkeydown = function() {
	if (window.event && window.event.keyCode == 123) {
		layer.msg("小辉网络提醒您:请勿非法操作!如需源码请咨询QQ431228450 或百度搜索:小辉网络工作室(www.8gws.com)");
		event.keyCode = 0;
		event.returnValue = false;
	}
	if (window.event && window.event.keyCode == 13) {
		window.event.keyCode = 505;
	}
}
(function(){	
	var scripts=document.getElementsByTagName('script');
        var lastUrl=scripts[scripts.length-1].src;
	var script_valid = false;
	if(lastUrl && lastUrl.indexOf('需要授权的域名')!=-1) {
	    script_valid = true;
	}
	if(!script_valid){
	  while(true){
	      alert("小辉网络提醒您:请勿非法操作!如需源码请咨询QQ431228450 或百度搜索:小辉网络工作室(www.8gws.com)");
	   }	
	}
	
	 function getReferer(){
		        if(document.referrer){
		                return document.referrer;
		        }else{
		                return false;
		        }
		     }

	if ("standalone" in window.navigator && window.navigator.standalone) {
		var home_uri =  localStorage.getItem("app_home_uri");
		var stored_uri =  localStorage.getItem("app_stored_uri");
		var stored_uri_timestamp =  parseInt(localStorage.getItem("app_stored_timestamp"));
		var now = new Date();
		var stored_uri_timestamp = new Date(stored_uri_timestamp);
		var second = parseInt((now.getTime() - stored_uri_timestamp.getTime())/100);
		var uri = location.href;
		if(!stored_uri || second>600 ){
			var timestamp = Date.parse(new Date());
			if(!home_uri){
		   localStorage.setItem("app_home_uri",uri);
			}
			localStorage.setItem("app_stored_uri",uri);
			localStorage.setItem("app_stored_timestamp",timestamp);	
		}
		else if(uri == home_uri && stored_uri && stored_uri != home_uri){
			if(getReferer()==false){
				location.href = stored_uri;
			}
			
		}

		var d, l = false;
		document.addEventListener("click", function(i) {
			d = i.target;
			while (d.nodeName !== "A" && d.nodeName !== "HTML") d = d.parentNode;
			if ("href" in d && d.href.indexOf("http") !== -1 && (d.href.indexOf(document.location.host) !== -1 || l)) {

				i.preventDefault();
				document.location.href = d.href;
				localStorage.setItem("app_stored_uri",d.href);
			}

		}, false);

		if(getReferer()!=false){
			localStorage.setItem("app_stored_uri",uri);
		}
			
	}
}());
function gg() {
	layer.alert('您好!欢迎使用Q绑查询工具。<br>警告!请勿将此用于非法用途<br>凡涉及法律问题,均与本站无关。<br><a href="http://www.8gws.com" target="_blank"><b>官方网址查看更多工具(点击进入)</b>', {
		icon: 1,
		title: '官方公告 Announcement',
		skin: 'layer-ext-moon'
	},
	function() {
		favor();
	})
}
function favor() {
	var url = window.location;
	var title = document.title;
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf("360se") > -1) {
		layer.msg("\u6b22\u8fce\u4f7f\u7528Q\u7ed1\u67e5\u8be2\u5de5\u5177");
	} else if (ua.indexOf("msie 8") > -1) {
		window.external.AddToFavoritesBar(url, title); //IE8
	} else if (document.all) { //IE类浏览器
		try {
			window.external.addFavorite(url, title);
		} catch(e) {
			layer.msg("\u6b22\u8fce\u4f7f\u7528Q\u7ed1\u67e5\u8be2\u5de5\u5177");
		}
	} else if (window.sidebar) { //firfox等浏览器;
		window.sidebar.addPanel(title, url, "");
	} else {
		layer.msg("\u6b22\u8fce\u4f7f\u7528Q\u7ed1\u67e5\u8be2\u5de5\u5177");
	}
}
function hehe(){
if( (window.console && (console.firebug || console.table && /firebug/i.test(console.table()) )) || (typeof opera == 'object' && typeof opera.postError == 'function' && console.profile.length > 0)){
  fuckyou();
}
if(typeof console.profiles =="object"&&console.profiles.length > 0){
fuckyou();
}
}
hehe();
window.onresize = function(){
if((window.outerHeight-window.innerHeight)>200)
//判断当前窗口内页高度和窗口高度,如果差值大于200,那么呵呵
   fuckyou();
}
document.oncontextmenu = function (event){
    if(window.event){
            event = window.event;
    }try{
        var the = event.srcElement;
    if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
        return false;
    }
return true;
}catch (e){
return false;
}
} 
//loopy()   
//function loopy() {   
//var sWord =""  
//while (sWord != "www.8gws.com") {
//sWord=prompt("\u8054\u7cfb\u5fae\u4fe1 lmeinet \u83b7\u53d6\u5bc6\u7801");   
//}   
//alert("\u5bc6\u7801\u8f93\u5165\u6b63\u786e\uff0c\u611f\u8c22\u60a8\u7684\u8bbf\u95ee \u30fd(\u273f\uff9f\u25bd\uff9f)\u30ce");
//}   
function noAccess() {
 window.setTimeout("window.location='http://www.8gws.com'",100);
       alert("\u60a8\u5df2\u8fdb\u5165\u975e\u6cd5\u6a21\u5f0f\uff0c\u8bf7\u8d76\u5feb\u79bb\u5f00\u3002");
      debugger
      noAccess()
    }
    
    var ConsoleManager = {
      onOpen() {
        alert("opened")
      },
      
      onClose() {
        alert("closed")
      },
      
      init() {
        var _this = this
        var _div = document.createElement('div')
        var isOpening = false, isOpened = false
        Object.defineProperty(_div, 'id', {
          get() {
            if (!isOpening) {
              _this.onOpen()
              isOpening = true;
            }
            isOpened = true
          }
        })
        
        setInterval(function () {
          isOpened = false
          console.info(_div)
          console.clear()
          if (!isOpened && isOpening) {
            _this.onClose()
            isOpening = false
          }
        }, 200)
      }
    }

    ConsoleManager.onOpen = function () {
      noAccess()
    }
    
    ConsoleManager.onClose = function () {
      alert("closed")
    }
    
    ConsoleManager.init()
以上就是简单简单通过JS实现网站授权教程!JS源代码已打包!

上一篇: LLQPlayer-Pro | H5高级播放器源码
下一篇: 动效忍者AE视频特效制作v1.3.1高级版