首页 > 其他分享 >js 禁止复制打印

js 禁止复制打印

时间:2023-08-29 17:55:29浏览次数:35  
标签:body none 打印 js filter 复制 blur document event

/*
NoPrint.js V1.0
Created by PDFAntiCopy.com
*/
const noPrint = true;
const noCopy = true;
const noScreenshot = true;
const autoBlur = false;
if (noCopy) 
{ 
    document.body.oncopy = function(){return false}; 
    document.body.oncontextmenu = function(){return false}; 
    document.body.onselectstart = document.body.ondrag = function(){
        return false;
    }
     document.onkeydown = function() {
        if((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 83) {
            event.preventDefault();
        }
        if((event.ctrlKey == true || event.metaKey == true) && event.code == 83) {
            event.preventDefault();
        }
    }
}

if (noPrint) 
{     
   var c=document.createElement("span");
   c.style.display="none";
   c.style.postion="absolute";
   c.style.background="#000";
    var first=document.body.firstChild;
    var wraphtml=document.body.insertBefore(c,first);
  c.setAttribute('width', document.body.scrollWidth);
  c.setAttribute('height', document.body.scrollHeight);
     c.style.display="block";
     var cssNode3 = document.createElement('style'); 
    cssNode3.type = 'text/css'; 
    cssNode3.media = 'print'; 
    cssNode3.innerHTML ='body{display:none}';
        document.head.appendChild(cssNode3);     
}             
    
var cssNode2 = document.createElement('style'); 
cssNode2.type = 'text/css'; 
cssNode2.media = 'screen'; 
cssNode2.innerHTML ='div{-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}';
document.head.appendChild(cssNode2);
document.body.style.cssText="-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;";
     

function toBlur()
{
    if (autoBlur)
    document.body.style.cssText="-webkit-filter: blur(5px);-moz-filter: blur(5px);-ms-filter: blur(5px);-o-filter: blur(5px);filter: blur(5px);"
}

function toClear()
{
    document.body.style.cssText="-webkit-filter: blur(0px);-moz-filter: blur(0px);-ms-filter: blur(0px);-o-filter: blur(0px);filter: blur(0px);"
}

document.onclick = function(event){
     toClear();
}
 
document.onmouseleave = function(event){
    toBlur();
}

document.onblur = function(event){
     toBlur();
}

document.addEventListener('keyup', (e) => {
    if (e.key == 'PrintScreen') {
        if (noScreenshot)
        {
        navigator.clipboard.writeText('');
        
      }
    }
});

document.addEventListener('keydown', (e) => {
    if (e.ctrlKey && e.key == 'p') {
        if (noPrint)
            {
            e.cancelBubble = true;
            e.preventDefault();
            e.stopImmediatePropagation();
          }
    }
});

来自 PDFAntiCopy.com

标签:body,none,打印,js,filter,复制,blur,document,event
From: https://www.cnblogs.com/dekui/p/17665520.html

相关文章

  • 关于Newtonsoft.Json的随笔
    在工作中一些陈旧项目,难免引用了一些很老版本,在一次升级中,项目引用的Newtonsoft.Json.dll突然少了一些method和class1,原来的:(咱也不懂为啥没有版本号嘞 2,升级后的 问题:1,原来使用的函数不存在,但是其实还在,换地方了而已,以下是修改:Newtonsoft.Json.JavaScriptConvert.Seria......
  • login;jsessionid=node07a53tu5ba3vd9k0wmsboxmq20.node0
    问题描述:shiro重定向到登入页面,登入地址出现了jsessionid=node07a53tu5ba3vd9k0wmsboxmq20.node0 解决方案:sessionManger中sessionIdUrlRewritingEnabled设置为false即可;<beanid="sessionManager"class="org.apache.shiro.web.session.mgt.DefaultWebSessionManage......
  • js面向对象浅析-表单生成
    js面向对象浅析-表单生成前言:这里就表单生成器的案例对js面向对象分析一下。。。(function(window){varFormBuilder=function(data){this.data=data;};window.FormBuilder=FormBuilder;})(window);FormBuilder.prototype.create=function(){va......
  • 百度编辑器 从word中复制内容带多张图片
    ​ 在之前在工作中遇到在富文本编辑器中粘贴图片不能展示的问题,于是各种网上扒拉,终于找到解决方案,在这里感谢一下知乎中众大神以及TheViper。通过知乎提供的思路找到粘贴的原理,通过TheViper找到粘贴图片的方法。其原理为一下步骤:监听粘贴事件;【用于插入图片】获取光标位置;【......
  • redis主从复制
    目录一什么是主从复制1.1主从复制:一主一从,一主多从1.2特点1.3Redis主从复制的作用二主从原理2.1主库是否要开启持久化(一般情况要开启)3.2方式一3.3方式二:配置文件方式一什么是主从复制redis单实例--->容易产生机器故障;容量瓶颈;QPS(每秒查询率)瓶颈1.1主从复制:一主一......
  • 11个有趣且实用的js库
    大家好,今天给大家分享几个前端实用的库。为了帮助你节省一些时间并提高工作效率,下面这些插件库你一定能用的上!1.BigPictureBigPicture是一款轻量级且独立于框架的JavaScript图像/视频查看器插件。可以使用<img>标签以及背景图像,支持Youtube、Vimeo、直接视频链接、任何......
  • Gson读取json字符串中结果需要转泛型的情况解决方案
    原始代码:Gsongson=newGson();ArrayList<Fld>fixed=gson.fromJson(newFileReader(headFilePath),ArrayList.class);for(Fldfld:fixed){intfld_len=fld.getFld_len();}错误显示:com.g......
  • 直播平台开发,利用原生JS实现回到顶部以及吸顶效果
    直播平台开发,利用原生JS实现回到顶部以及吸顶效果  <style>    .box1{      width:1200px;      height:800px;            margin:0auto;    }    .box2{      width:1200px; ......
  • Gson与FastJson详解
    Gson与FastJson详解Java与JSON做什么?将Java中的对象快速的转换为JSON格式的字符串.将JSON格式的字符串,转换为Java的对象.Gson将对象转换为JSON字符串转换JSON字符串的步骤:引入JAR包在需要转换JSON字符串的位置编写如下代码即可:Stringjson=newGson().toJSON(要转换的对象......
  • js找出一定范围内的全部素数(埃拉托斯特尼筛法Sieve of Eratosthenes)
    最近在看js的基础,看到函数这一章的时候,看到了这种写法。 原文链接:https://zh.javascript.info/function-basics突然懵了个B,js还能这么写。然后问了下chat,才想起来这是js的标签用法。在JavaScript中,标签(label)是一种标识符,用于标记代码中的特定位置,通常是在循环语句中使用。标......