常用网页代码

禁止右键和复制文字代码

<body oncontextmenu="return false" onselectstart="return false">

禁止“另存为”命令
  在<body>...</body>标签之间加入如下代码,可以使“另存为”命令不能顺利执行。
    <noscript>
  <iframe scr=″*.htm″></iframe>
  </noscript>

  加入上述代码后,当执行“另存为”命令时,会弹出“保存网页时出错”的对话框。

防止被人frame
<SCRIPT LANGUAGE=JAVASCRIPT><!-- 
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>

ENTER键可以让光标移到下一个输入框
       <input onkeydown="if(event.keyCode==13)event.keyCode=9">

IE标题栏随机变换文字
把下面代码制作出JS文件,然后再包含到网页里去

_CH_DocumentTitles = new Array('再长的路,一步步也能走完,再短的路,不迈开双脚也无法到达。','任何业绩的质变都来自于量变的积累。','成功不是将来才有的,而是从决定去做的那一刻起,持续累积而成。');
_CH_DocumentTitleId = Math.floor(Math.random()*_CH_DocumentTitles.length);
document.title = 'MHCY工作室---深圳网站建设 | '+_CH_DocumentTitles[_CH_DocumentTitleId]; 

关闭窗口
<a href="javascript:window.close();">关闭窗口</a>

IE地址栏前换成自己的图标
       <link rel="Shortcut Icon" href="http://www.mhcy.net/favicon.ico">

可以在收藏夹中显示出你的图标
       <link rel="Bookmark" href="http://www.mhcy.net/favicon.ico">

加入收藏夹

<A href="javascript:window.external.addFavorite ('http://mhcy.51.net',
'MHCY工作室')">将本站加入收藏夹</A>

设为首页

<A href="http://netcomm.net.cn/index.html"
onclick="this.style.behavior='url (#default#homepage)';
this.sethomepage('http://mhcy.51.net');">设为首页</A>

防止点击空链接时,页面往往重置到页首端。
     
       代码“javascript:void(null)”代替原来的“#”标记


屏蔽拷屏,不断地清空剪贴板

在body标签里加上onload="setInterval('clipboardData.setData(\'Text\',\'\')',100)"


无窗口全屏

onload="moveTo(0,0);resizeTo(screen.availWidth,screen.availHeight);
resizeTo(screen.availWidth+screenLeft*2,screen.availHeight+
(screen.availHeight-document.body.offsetHeight));moveTo(-screenLeft,-screenTop)" scroll="no"


屏蔽网站的打印功能

<style>
@media print {
* { display: none }
}
</style>

屏蔽IE6.0 图片上自动出现的保存图标

方法一:
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
方法二:
<img galleryimg="no">

状态栏固定信息


把<body>区域中的内容改为
<body bgcolor="#fef4d9" onmouseover="self.status='欢迎光临“南京有线电视台”--http://www.njcatv.net';return true">

随机替换图片
<script>
  document.write('<img src="img/'+parseInt(Math.random()*(5))
  +'.gif"height="40" width="50">')
</script>

 图片文件名为0.gif 1.gif 2.gif 3.gif 4.gif

窗口定时关闭
先将如下代码网页文件的区:
  <script language="JavaScript">
  function closeit() { setTimeout("self.close()",10000) //毫秒 }
  </script>
然后再在<body>标内加入如:<body onload="closeit()">

网页自动关闭
  <html>
  <head>
  <object id=closes type="application/x-oleobject"
  classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
  <param name="Command" value="Close">
  </object>
  </head>
  <body onload="window.setTimeout('closes.Click()',10000)">
  这个窗口会在10秒过后自动关闭,而且不会出现提示.
  </body>
  </html>


网页自动刷新
在head部记入
  <META HTTP-EQUIV="Refresh" content="20">
其中20为20秒后自动刷新,你可以更改为任意值。

网页自动转页
    <META HTTP-EQUIV="Refresh" CONTENT="时间(秒);URL=地址">

网页不会被缓存

HTMl网页
<META HTTP-EQUIV=pragma CONTENT=no-cache>
<META HTTP-EQUIV=Cache-Control CONTENT=no-cache, must-revalidate>
<META HTTP-EQUIV=expires CONTENT=Wed, 26 Feb 1997 08:21:57 GMT>
或者<META HTTP-EQUIV=expires CONTENT=0>
ASP网页
 Response.Expires = -1
 Response.ExpiresAbsolute = Now() - 1
 Response.cachecontrol = no-cache
PHP网页
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT;
header(Cache-Control: no-cache, must-revalidate;
header(Pragma: no-cache;

最小化、最大化、关闭窗口
<object id=hh1 classid=clsidDB880A6-D8FF-11CF-9377-00AA003B7A11>
<param name=Command value=Minimize></object>
<object id=hh2 classid=clsidDB880A6-D8FF-11CF-9377-00AA003B7A11>
<param name=Command value=Maximize></object>
<OBJECT id=hh3 classid=clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11>
<PARAM NAME=Command value=Close></OBJECT>
<input type=button value=最小化 onclick=hh1.Click()>
<input type=button value=最大化 onclick=hh2.Click()>
<input type=button value=关闭 onclick=hh3.Click()>

弹出窗口

---------
<a href="#" onclick="javascript:window.open('news_show.asp','','
resizable=yes, scrollbars=yes,status=no,toolbar=no,menubar=no,
location=no,width=400,height=300')">文本内容</a>
---------
<a href="#" onClick="MM_openBrWindow('news_show.asp','',
'scrollbars=yes,width=570,height=500')" class="news">文本内容</a>

---------

<script language= "javascript">
function newpage(htmlurl) {
var newwin=window.open(htmlurl,"newWin","toolbar=no,location=no,directories=no,status=no,
menubar=no,scrollbars=yes,resizable=no,top=100,left=100,
width=634,height=450");
newwin.focus();
return false;
}

<A href="http://www.mhcy.net/products_af_show.asp" onClick="return newpage(this.href);">
products </A>

包含网页

<iframe id="frm" src="http://www.mhcy.net/news.asp" scrolling="no" width="179" height="112"
frameborder="0"></iframe>

Iframe 透 明 背 景


IFRAME里加上属性:allowtransparency="true"
IFRAME的SRC网页加上:
<style type="text/css">
<!-- BODY {background:none transparent;}-->
</style>




超级链接的滚动提示框

<a href="http://mhcy.51.net"
onmouseover="showtip(this,event,'文本内容')"
onmouseout="hidetip()">MHCY工作室
</a><br>
<div id="tooltip" style="position:absolute;visibility:hidden;
clip:rect(0 150 50 0);width:149px;
background-color:lightyellow; height: 19px; left: 77px; top: 96px">
<layer name="nstip" width=1000px bgcolor="lightyellow"></layer>
</div>

<script>
if (!document.layers&&!document.all)
event="test"
function showtip(current,e,text) //显示链接的说明
{
if (document.all&&document.readyState=="complete") //针对IE
{
//显示跑马灯,内容就是提示框的内容
document.all.tooltip.innerHTML='<marquee style="border:1px solid
black">'+text+'</marquee>'
document.all.tooltip.style.pixelLeft=event.clientX+document.
body.scrollLeft+10
document.all.tooltip.style.pixelTop=event.clientY+document.
body.scrollTop+10
document.all.tooltip.style.visibility="visible"
}

else if (document.layers) //针对Netscape
{
document.tooltip.document.nstip.document.write('<b>'+text+'</b>')
document.tooltip.document.nstip.document.close()
document.tooltip.document.nstip.left=0
currentscroll=setInterval("scrolltip()",100)
document.tooltip.left=e.pageX+10
document.tooltip.top=e.pageY+10
document.tooltip.visibility="show"
}
}
function hidetip() //隐藏链接的说明
{
if (document.all)
document.all.tooltip.style.visibility="hidden"
else if (document.layers){
clearInterval(currentscroll)
document.tooltip.visibility="hidden"
}
}

function scrolltip() //在Netscape中实现提示框内容的滚动显示
{
if (document.tooltip.document.nstip.left>=-document.tooltip.
document.nstip.document.width)
document.tooltip.document.nstip.left-=5
else
document.tooltip.document.nstip.left=150
}
</script>

 

 

常用网页代码 本文结束

  [ 打印 ] [ 关闭 ]