在前端開發(fā)中码党,F(xiàn)12審查元素的情況下德崭,大家都可以隨機(jī)更改一部分頁面的代碼,注入惡意JS等等揖盘,這種情況避免也不難眉厨,雖然還能看到一部分H5源碼,但是無法修改兽狭。
一憾股、屏蔽F12 審查元素
<script>
document.onkeydown = function () {
? ? if (window.event && window.event.keyCode == 123) {
? ? ? ? alert("F12被禁用");
? ? ? ? event.keyCode = 0;
? ? ? ? event.returnValue = false;
? ? }
? ? if (window.event && window.event.keyCode == 13) {
? ? ? ? window.event.keyCode = 505;
? ? }
? ? if (window.event && window.event.keyCode == 8) {
? ? ? ? alert(str + "\n請(qǐng)使用Del鍵進(jìn)行字符的刪除操作!");
? ? ? ? window.event.returnValue = false;
? ? }
}
</script>
二箕慧、屏蔽右鍵菜單
<script>
document.oncontextmenu = function (event) {
? ? if (window.event) {
? ? ? ? event = window.event;
? ? }
? ? try {
? ? ? ? var the = event.srcElement;
? ? ? ? if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? return true;
? ? } catch (e) {
? ? ? ? return false;
? ? }
}
三服球、屏蔽粘貼
<script>
document.onpaste = function (event) {
? ? if (window.event) {
? ? ? ? event = window.event;
? ? }
? ? try {
? ? ? ? var the = event.srcElement;
? ? ? ? if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? return true;
? ? } catch (e) {
? ? ? ? return false;
? ? }
}
</script>
四、屏蔽復(fù)制
<script>
document.oncopy = function (event) {
? ? if (window.event) {
? ? ? ? event = window.event;
? ? }
? ? try {
? ? ? ? var the = event.srcElement;
? ? ? ? if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? return true;
? ? } catch (e) {
? ? ? ? return false;
? ? }
}
</script>
五颠焦、屏蔽剪切
<script>
document.oncut = function (event) {
? ? if (window.event) {
? ? ? ? event = window.event;
? ? }
? ? try {
? ? ? ? var the = event.srcElement;
? ? ? ? if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? return true;
? ? } catch (e) {
? ? ? ? return false;
? ? }
}
六斩熊、屏蔽選中
<script>
document.onselectstart = function (event) {
? ? if (window.event) {
? ? ? ? event = window.event;
? ? }
? ? try {
? ? ? ? var the = event.srcElement;
? ? ? ? if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? return true;
? ? } catch (e) {
? ? ? ? return false;
? ? }
}
</script>