无论何时开发 HTML 页面或 CSS 代码段,都要记住你或者其它人几乎肯定需要在某一天修改它。简单的文本 Web 页面通常容易阅读和修改,但是带有图形、表格和其它布局技巧的复杂页面可能相当难以解释。
在涉及使 HTML 代码更容易理解和维护时,一致的缩进甚至可能比注释更重要。
设置网页自动关闭的方法是在一定的时间调用全局 window.close() 方法,关闭当前窗口。
<body
oncontextmenu="self.event.returnValue"
="false"
onselectstart="return
false"
></body>
另一种禁用右键的方法如下。
<body oncontextmenu="return false"></body>
<!-- 禁用右键 : -->
<script>
function stop() {
return false; // 返回 false ,表示禁用
}
document.oncontextmenu = stop; // 监听 oncontextmenu 方法
</script>
禁止"另存为"命令需要在目标网页末尾" </body></html> "的标签前面加上如下代码,可以使"另存为"命令不能顺利执行。
<noscript> <iframe scr="*.htm"></iframe> </noscript>
同理,取消选取、防止复制方法如下: oncopy="return false;" oncut="return false;" 。
// 禁用右键菜单
oncontextmenu = 'return false';
// 禁用拖拽
ondragstart = 'return false';
// 禁用选取
onselectstart = 'return false';
// 禁用选取
onselect = 'document.selection.empty()';
// 禁用复制
oncopy = 'document.selection.empty()';
// 禁用复制
onbeforecopy = 'return false';
// 禁用鼠标
onmouseup = 'document.selection.empty()';
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.onmousedown = norightclick; // for all others
window.open(
'page.html',
'newWindow',
'height=300, width = 400, top = 0, left = 0, toolbar = no,menubar = no ,scrollbars = no, resizable = no, location = no,status = no',
);