gpt4 book ai didi

javascript - 是否可以停止从打印预览中复制文本?

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:05 25 4
gpt4 key购买 nike

我试图阻止用户在打印屏幕上选择和复制文本。

我使用这个 CSS 来禁用选择。

.disable-select {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by any browser but < IE9 */
}

<body class="disable-select">
...
</body

这个 jquery 可以防止在我的网页中复制、粘贴和右键单击选项

$(document).bind('contextmenu cut copy', function (e) {
e.preventDefault();
});

它在网页上工作,但是当我们按 ctrl+p 打印网页并进入打印选项屏幕时,上面的代码都不能在这个屏幕上工作

stop text selection and copy on this print screen

最佳答案

不可能影响打印预览。你可以take a look here

但是您可以阻止人们将那段文字完全放在打印页面中。像这样:

.disable-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@media print{
.disable-select{
display:none
}
}

编辑

有一种方法可以做到这一点,更像是一种技巧而不是适当的 CSS 功能,但它只适用于现代浏览器。

显然,使用 CSS 过滤器会阻止用户在打印预览中选择文本

@media print{
.disable-text{
filter:grayscale(100%)
}
}

CSS Filter compatibility table

编辑 2

同时在打印场景中将固定元素的位置设置为相对。


@media print{
.disable-text{
filter:grayscale(100%)
}
.fixed-elements{
position: relative;
}
}

编辑 3

或者另一种防止固定元素被更改的解决方案是将 disable-text 类添加到 HTML 标记或要防止文本被复制的特定 div。

关于javascript - 是否可以停止从打印预览中复制文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56145697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com