防止从iframe复制内容

时间:2019-12-25 22:59:19

标签: javascript jquery html

我想防止复制iframe中加载的内容。我正在使用以下代码[per this answer],它可以正常工作。

<html>
<head>
    <title>Test</title>
    <script type='text/javascript' src='//code.jquery.com/jquery-1.8.3.js'></script>
    <script type='text/javascript'>
        $(window).load(function () {            
            var $frame = $("#tif");
            $frame.contents().bind("copy", function (e) {
                e.preventDefault();
            });
        });
    </script>
</head>
<body>
<iframe src="whatever.com" height="768" width="1366" id="tif"></iframe>
</body>
</html>

但是当以pdf文件作为源文件时,以上代码将失败。有什么建议吗?

0 个答案:

没有答案