Home Web Front-end JS Tutorial JavaScript代码实现禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt_javascript技巧

JavaScript代码实现禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt_javascript技巧

May 16, 2016 pm 03:32 PM
shift Right click Paste choose

废话不多说了直接给大家贴代码了。

代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

<script language="JavaScript">

<!--

//js禁用某些键的代码

//www.jb51.net

function key(){

if(event.shiftKey){

window.close();}

//禁止Shift

if(event.altKey){

window.close();}

//禁止Alt

if(event.ctrlKey){

window.close();}

//禁止Ctrl

return false;}

document.onkeydown=key;

if (window.Event)

document.captureEvents(Event.MOUSEUP);

function nocontextmenu(){

event.cancelBubble = true

event.returnValue = false;

return false;}

function norightclick(e){

if (window.Event){

if (e.which == 2 || e.which == 3)

return false;}

else

if (event.button == 2 || event.button == 3){

event.cancelBubble = true

event.returnValue = false;

return false;}

}

//禁右键

document.oncontextmenu = nocontextmenu; // for IE5+

document.onmou<a href="http://www.jb51.net/article/1141.html" target="_blank" class="infotextkey">sed</a>own = norightclick; // for all others

//-->

</script>

Copy after login


1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键特效

no
可用于Table

2. 取消选取、防止复制

3. onpaste="return false" 不准粘贴

4. oncopy="return false;" oncut="return false;" 防止复制

PS:JS防止后退,刷新,关闭的解决办法

1

2

3

4

5

6

7

8

9

10

11

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html><head>

<title> New Document </title>

</head>

<script language="javascript">

function RunOnBeforeUnload() {window.onbeforeunload = function(){ return '将丢失未保存的数据!'; } }

</script>

<body onload="RunOnBeforeUnload()">

刷新,关闭,后退,F5 测试

</body>

</html>

Copy after login

虽然onbeforeunload这个事件已经Web标准被淘汰,但目前能实现这个效果的也就只有这个事件.还好浏览器都能很好的支持.

测试结果:

IE6.0,FireFox,Chrome通过

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open the right-click menu through shortcut keys How to open the right-click menu through shortcut keys Jan 14, 2024 pm 03:12 PM

When our mouse temporarily loses its function, how to use keyboard shortcuts to open the right-click menu? There are two methods. One is to press the Shift+F10 shortcut key to adjust the right-click menu, and the other is to use the keyboard shortcut between windows and ctrl. Directory keys can also be used. Let’s take a look at the specific tutorial below. The first method of using keyboard shortcuts to open the right-click menu: 1. When no file is selected on the computer desktop, press the button marked in red circle on the keyboard in the picture below. This button is the button to quickly open the right-click menu. 2. You can open the right-click menu on the desktop. If you need to select an item, just use the mouse to select it. Second method 1. In fact, we can use the "Shift+F10" shortcut key to adjust the right-click menu 2

Right click not working in Word or PowerPoint [FIXED] Right click not working in Word or PowerPoint [FIXED] Feb 27, 2024 pm 02:19 PM

Some Office users have reported that their right mouse button does not work properly in Word and PowerPoint. When they right-click on an empty space or element in the document, they don't get any context menu with options for paste options, fonts, format background, format image, create new annotation, and more. Some users have reported that when they press the right mouse button, the context menu appears for 1-2 seconds and then quickly disappears before they click on any option. Why doesn't my right-click work in Microsoft Office? If right-clicking does not work in Office applications such as Word and PowerPoint, it is usually caused by a third-party add-in. If your mouse is not in the correct

Can wallpaper engine be shared among families? Can wallpaper engine be shared among families? Mar 18, 2024 pm 07:28 PM

Does Wallpaper support family sharing? Unfortunately, it cannot be supported. Still, we have solutions. For example, you can purchase with a small account or download the software and wallpapers from a large account first, and then change to the small account. Simply launching the software is perfectly fine. Can wallpaperengine be family shared? Answer: Wallpaper does not currently support the family sharing function. 1. It is understood that WallpaperEngine does not seem to be suitable for family sharing environments. 2. In order to solve this problem, it is recommended that you consider purchasing a new account; 3. Or download the required software and wallpapers in the main account first, and then switch to other accounts. 4. Just open the software with a light click and it will be fine. 5. You can view the properties on the above web page&quot;

iBatis vs. MyBatis: Which one is better for you? iBatis vs. MyBatis: Which one is better for you? Feb 19, 2024 pm 04:38 PM

iBatis vs. MyBatis: Which should you choose? Introduction: With the rapid development of the Java language, many persistence frameworks have emerged. iBatis and MyBatis are two popular persistence frameworks, both of which provide a simple and efficient data access solution. This article will introduce the features and advantages of iBatis and MyBatis, and give some specific code examples to help you choose the appropriate framework. Introduction to iBatis: iBatis is an open source persistence framework

How to set lock screen wallpaper on wallpaper engine? How to use wallpaper engine How to set lock screen wallpaper on wallpaper engine? How to use wallpaper engine Mar 13, 2024 pm 08:07 PM

WallpaperEngine is a software commonly used to set desktop wallpapers. Users can search for their favorite pictures in WallpaperEngine to generate desktop wallpapers. It also supports adding pictures from the computer to WallpaperEngine to set them as computer wallpapers. Let’s take a look at how wallpaperengine sets the lock screen wallpaper. Wallpaperengine setting lock screen wallpaper tutorial 1. First enter the software, then select installed, and click "Configure Wallpaper Options". 2. After selecting the wallpaper in separate settings, you need to click OK on the lower right. 3. Then click on the settings and preview above. 4. Next

Win10 right click does not run as administrator Win10 right click does not run as administrator Jan 06, 2024 pm 10:29 PM

Many friends who use win10 system find that when they right-click on the desktop, there is no option to run as administrator. So how do we restore this option? In fact, we only need to disable and close the account in the settings. Specifically Let’s take a look at the tutorial. Method to restore Win10 by right-clicking and running as administrator: 1. Right-click this computer, also known as My Computer, on the desktop and select "Manage". 2. Expand to Computer Management - System Tools - Local Users and Groups - Users, find and open Administrator on the right. 3. In the Administrator properties interface, uncheck "Account is disabled" and click OK. 4. After completing the settings, go to Administrator

The first choice for CS players: recommended computer configuration The first choice for CS players: recommended computer configuration Jan 02, 2024 pm 04:26 PM

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

Is there any virus when watching wallpaper engine movies? Is there any virus when watching wallpaper engine movies? Mar 18, 2024 pm 07:28 PM

Users can download various wallpapers when using WallpaperEngine, and can also use dynamic wallpapers. Many users do not know whether there are viruses when watching videos on WallpaperEngine, but video files cannot be used as viruses. Is there any virus when watching movies on wallpaperengine? Answer: No. 1. Just video files cannot be used as viruses. 2. Just make sure to download videos from trusted sources and maintain computer security measures to avoid the risk of virus infection. 3. Application wallpapers are in apk format, and apk may carry Trojan viruses. 4. WallpaperEngine itself does not have viruses, but some application wallpapers in the creative workshop may have viruses.

See all articles