Html加水印和禁用复制和右键(jquery.watermark.js)

近期遇到一个需求,需要在页面背景加上自己的水印和禁止用户在页面复制粘贴


 解决:

水印使用的是jquery.watermark.js插件,这个插件可以在html背景上加水印,同时可以设置相关属性值。

相关代码如下:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>test</title>
    <style type="text/css">
        body, html{
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
    <script src="http://code.jquery.com/jquery-git.js"></script>
    <script src="jquery.watermark.js"></script>
</head>
<body >
     <script type="text/javascript">
        $('body').watermark({
            texts : ["这是测试", "这是测试2"], //水印文字
            textColor : "#d2d2d2", //文字颜色
            textFont : '14px 微软雅黑', //字体
            width : 100, //水印文字的水平间距
            height : 100,  //水印文字的高度间距(低于文字高度会被替代)
            textRotate : -30 //-90到0, 负数值,不包含-90
        })
     </script>
</body>
</html>

 注意:这个插件需要在引用了jquery的基础上使用


 效果如下:


禁用复制和右键代码如下:

     //禁止复制和右键另存为
        function iEsc() { return false;}
        function iRec() { return true;}
        function DisableKeys() {
            if (event.ctrlKey || event.shiftKey || event.altKey) {
                window.event.returnValue = false;
                iEsc();
            }
        }
        document.ondragstart = iEsc;
        document.onkeydown = DisableKeys;
        document.oncontextmenu = iEsc;
        if (typeof document.onselectstart != "undefined")
            document.onselectstart = iEsc;
        else {
            document.onmousedown = iEsc;
            document.onmouseup = iRec;
        }

结束

转载于:https://www.cnblogs.com/zktww/p/11399782.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值