HTML代码片段

HTML代码片段

复制代码
按钮类
    后退、前进按钮
    返回按钮
    几种刷新按钮
    警告框显示源代码
    链接按钮
    打开新窗口
    打印
    新窗口延迟打开
    背景色变换
表单类
    点击清空文字
    关闭输入法
链接
    双击打开链接
    超链接鼠标形状
页面
    不准粘贴
    防止复制
    彻底屏蔽鼠标右键,无右键菜单
    取消选取以防止复制
    禁止查看源码
    随机选择背景色
    自定义网页图标
    自定义网页收藏夹图标
    内嵌式框架-网页中调用另外网页
    页面定时跳转
    防止被人frame
-------------------------------代码-------------------------------------------------
不准粘贴
<body onpaste="return false;">

防止复制
<body oncopy="return false;">

后退、前进按钮
<input type="button" value="后退" onClick="history.go(-1)">
<input type="button" value="前进" onClick="history.go( 1 );return true;">

返回按钮
<form>
    <input type="button" value="返回上一步" onClick="history.back(-1)">
</form>

禁止查看源码
<body oncontextmenu="return false">
</body>

关闭输入法
<input style=ime-mode:disabled>
说明:这段代码是在表格提交时用到的。也就是在输入数据时不可以使用其他输入法模式。

背景色变换
<form><input type="button" value="背景色变换" onClick="BgButton()"></form>
<script>
    function BgButton(){
        if (document.bgColor=='#00ffff')
        {
            document.bgColor='#ffffff';
        }
        else{
            document.bgColor='#00ffff';
        }
    }
</script>

彻底屏蔽鼠标右键,无右键菜单
<body oncontextmenu=window.event.returnvalue=false>
也可以用于网页中Table框架中
<table border oncontextmenu=return(false)><td>no</table>

打开新窗口
<input type="button" value="打开新窗口" onClick="NewWindow()">
<script>
    function NewWindow(){
        window.open("c01.htm","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");
    }
</script>


链接按钮
一: 打开标签
<input type="button" value="链接按钮1" onClick="window.open('http://www.baidu.com/', 'Sample', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=790,height=520,left=0,top=0')" name="input">
二: 打开标签
<input type="BUTTON" NAME="Button" value="链接按钮2" onClick="showModalDialog('http://www.baidu.com/')">
三: 在本页
<input type="submit" value="链接按钮3" onClick="location.href='http://www.baidu.com/'">

警告框显示源代码
<BUTTON onClick=alert(document.documentElement.outerHTML) style="width:110">警告框显示源代码</BUTTON>

打印
<input type=button value='打印' onClick="this.style.visibility='hidden';window.print();">
<input type=button value='打印' onClick="window.print();">

新窗口延迟打开
<input type=button value=新窗口延迟打开 onClick=javascript:setTimeout("window.open('http://www.baidu.com/')",10000)>

点击清空文字
<input type="text" name="artist" size=14 value="点击清空文字" onmouseover=this.focus() onfocus=this.select() onclick="if(this.value=='点击清空文字')this.value=''">

几种刷新按钮的方法
<input type=button value=刷新 onClick="history.go(0)">
<input type=button value=刷新 onClick="location.reload()">
<input type=button value=刷新 onClick="location=location">
<input type=button value=刷新 onClick="location.assign(location)">
<input type=button value=刷新 onClick="location.replace(location)">
<input type=button value=刷新 onClick="window.open('自身的文件','_self')">
<input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)>
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<form action="自身的文件"><input type=submit value=刷新></form>
<a id=a1 href="自身的文件"></a><input type=button value=刷新 onClick="a1.click()">

双击打开链接
<a href="i003.htm" onclick="return false;" ondblclick="window.open('i003.htm');">双击打开链接</a>

随机选择背景色
<script>
document.body.style.background=(["red","blue","pink","navy","gray","yellow","green","purple"])[parseInt(Math.random()*8)];
</script>

内嵌式框架-网页中调用另外网页
<object type="text/x-scriptlet" width="600" height="1000" data="http://www.baidu.com/"></object>

自定义网页图标
<link rel="shortcut icon" href="图标地址" type="image/x-icon />
<link rel="icon" href="图标地址" type="image/x-icon />
第一行是必需的,第二行是为了兼容

超链接鼠标形状
style="cursor:hand"
style="cursor:crosshair"
style="cursor:text"
style="cursor:wait"
style="cursor:move"
style="cursor:help"
style="cursor:e-resize"
style="cursor:n-resize"
style="cursor:nw-resize"
style="cursor:w-resize"
style="cursor:s-resize"
style="cursor:se-resize"
style="cursor:sw-resize"

页面定时跳转
<meta http-equiv="refresh" content="秒数;url=路径" />

取消选取以防止复制
<body onselectstart=return false>

自定义网页收藏夹图标
<link rel="Bookmark" href="图标地址">

防止被人frame
<script language=javascript><!--
if (top.location != self.location)top.location=self.location;
--></script>

网页将不能被另存为
<noscript><iframe src=*.html></iframe></noscript>
说明:<noscirpt>的用法很广,其中一条就是可以使JS广告失效。
复制代码
posted @ 2020-06-13 11:32  威武的大萝卜  阅读(397)  评论(0编辑  收藏  举报