JavaScript 设置网页无法复制的方法: 在 JavaScript 代码中设置禁用右键菜单, 复制, 选择等操作, 禁用 Ctrl+c 和 Ctrl+v 快捷键的使用, 通过这种方法就可以实现网页无法复制.
JavaScript 设置网页无法复制的方法代码如下:
- // 禁用右键菜单, 复制, 选择
- $(document).bind("contextmenu copy selectstart", function() {
- return false;
- });
- // 禁用 Ctrl+C 和 Ctrl+V(所有浏览器均支持)
- $(document).keydown(function(e) {
- if(e.ctrlKey && (e.keyCode == 65 || e.keyCode == 67)) {
- return false;
- }
- });
- // 设置 CSS 禁止选择 (如果写了下面的 CSS 则不需要这一段代码, 新版浏览器支持)
- $(function() {
- $("body").CSS({
- "-moz-user-select":"none",
- "-webkit-user-select":"none",
- "-ms-user-select":"none",
- "-khtml-user-select":"none",
- "-o-user-select":"none",
- "user-select":"none"
- });
- });
防止禁用 JavaScript 后失效, 可以写在 CSS 中 (新版浏览器支持, 并逐渐成为标准):
- body {
- -moz-user-select:none; /* Firefox 私有属性 */
- -webkit-user-select:none; /* WebKit 内核私有属性 */
- -ms-user-select:none; /* IE 私有属性 (IE10 及以后) */
- -khtml-user-select:none; /* KHTML 内核私有属性 */
- -o-user-select:none; /* Opera 私有属性 */
- user-select:none; /* CSS3 属性 */
- }
来源: http://www.css88.com/qa/javascript/11012.html