`

很有用的HTML+JavaScript代码

阅读更多
很有用的HTML+JavaScript代码
层的隐藏与显示

   只要设置style的display属性即可
   比如<div style="display:none" id="MyDiv">隐藏的层</div>
   如果要显示它可以通过脚本来控制
   window.document.getElementById("MyDiv").style.display = "";

禁止右键
  
   <body oncontextmenu="return false">

屏蔽页面中程序运行出错信息

   window.onerror = function()
   {
return true;
   }

得到当前显示器的分辨率

   window.srceen.width 得到屏幕的宽度
   window.srceen.height 得到屏幕的高度
   如果当前分辨率为800*600,window.srceen.width是800,window.srceen.height是600

定时运行特定代码

   setTimeout(Code,Timeout);
   setInterval(Code,Timeout);
   Code是一段字符串,里边是js代码,Timeout是时间间隔,单位是微秒
   setTimeout是从现在算起多少微秒后运行该代码(只运行一次)
   setInterval是每隔多少微秒运行一次代码

得到本页网址

   var Url = window.location.href;

保存当前页面的内容

   document.execCommand("SaveAs","","C:\\index.htm");

隐去浏览器中当鼠标移到图片上跳出的工具栏
<img galleryimg="no">
或者
<head>
<meta http-equiv="imagetoolbar" content="no">
</head>

打开,另存为,属性,打印"等14个JS代码

■打开■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> 
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■另存为■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■属性■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■打印■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>

■打印预览■ 71 
■页面设置■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■刷新■ 
<input type=button value=刷新 name=refresh onclick="window.location.reload()"> 
■导入收藏■ 
<input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,);> 
■导出收藏■ 
<input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,);> 
■加入收藏■ 
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹> 
■整理收藏夹■ 
<INPUT name=Submit2 onclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夹> 
■查看原文件■ 
<INPUT name=Button onclick=window.location = "view-source:" + window.location.href type=button value=查看源文件> 
■语言设置■ 
<INPUT name=Button onclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=语言设置> 
■前进■ 
<INPUT name=Submit onclick=history.go(1) type=submit value=前进> 
■后退■ 
<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>

■关闭窗体无提示■

<input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭窗体无提示>


出自:http://hi.baidu.com/Ư%B2%B4%C8%E7%B7%E7/blog/item/2a8d51a96b10befa1f17a262.html

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

不能点右键,不用CTRL+A,不能复制作!
<body oncontextmenu="window.event.returnValue=false" 
onkeypress="window.event.returnValue=false" 
onkeydown="window.event.returnValue=false" 
onkeyup="window.event.returnValue=false" 
ondragstart="window.event.returnValue=false" 
onselectstart="event.returnValue=false"> 
</body>

显示状态拦固定文字:
放在body前 
<base onmouseover="window.status='这里是Goaler的Blog系统,欢迎访问';return true"> 


用键盘打开网页 <script language=javascript>
document.onkeydown=gopage
var add="Admin/AddArticle.asp"
var logon="Admin/Logon.asp"
function gopage() {
if (event.keyCode==13) location=add
if (event.keyCode==38) location=logon
}
</script> 


根据内容自动调整iframe高度 有时为了方便使用Iframe,但被潜入的页面长度不是固定的,显示滚动条不仅影响美观还对用户操作带来不便,自动调整高度可以解决这个问题。^_^

function f_frameStyleResize(targObj)
{
var targWin = targObj.parent.document.all[targObj.name];
if(targWin != null)
{
var HeightValue = targObj.document.body.scrollHeight
if(HeightValue < 600){HeightValue = 600} //不小于600
targWin.style.pixelHeight = HeightValue;
}
}
function f_iframeResize()
{
bLoadComplete = true;
f_frameStyleResize(self);
}

var bLoadComplete = false;
window.onload = f_iframeResize;


禁止页面正文内容被选取 


<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return 
false"onmouseup="document.selection.empty()"> 


消除ie6自动出现的图像工具栏,设置 GALLERYIMG属性为false或no . 


<IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="no"> 


防止点击空链接时,页面往往重置到页首端。 


代码“javascript:void(null)”代替原来的“#”标记 


如何避免别人把你的网页放在框架中 


<script language=“javascript”><!--if (self!=top){top.location=self.location;} -->< /script> 


页面定时刷新 


<meta http-equiv="Refresh" content="秒" > 


页面定时转向新的地址 


<meta http-equiv="refresh" content="秒;URL=url"> 


关闭窗口,这个是不会弹出提示直接关的: 
把如下代码加入<body>区域中 


<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> 
<param name="Command" value="Close"> 
</object> 
<script language="JavaScript">function shutwin(){closes.Click();return;}</script> 
<a href="javascript:shutwin();">关闭本窗口</a> 


有时候好不容易写出来的程序代码被别人抄去,心里一定不好受。这还是小事,但如果在我们的源代码中有一些不希望让别人知道的内容,比如密码、Action的指向等,这些一旦被人利用,那后果有时是不堪设想的。而网页加密就是我们现在需要解决的问题。下面就我在网页制作中的一些经验向大家介绍一些简单的防范方法。 
禁止右键 
看到这里大家一定会想,这招有很多人介绍过了,而且破解的方法也有很多。但我这里要说的是另一种方法,而且我试了很多方法都没有能破解。具体如下: 


<html> 
<head> 
<script> 
function stop(){ 
alert("试试能破解吗?"); 
return false; 
} 
document.oncontextmenu=stop; 
</script> 
<boyd>你可以按右键、shift+F10和右ctrl左边的那个键试试!看能不能解。^_^</body> 


大家试试,看能不能破解!你可以将alert("试试能破解吗?");这句去掉,这样当按右键时就什么反应也没有了,就好像没有右键功能一样。 

禁示查看源代码 
我们已经禁了右键,但从"查看"菜单下的"源文件"中同样可以看到源代码,下面我们就来解决这个问题: 
其实这只要使用一个含有<frame></frame>标记的网页便可以达到目的。 


<frameset> 
<frame src="你要保密的文件的URL"> 
</frameset> 


这样当有人使用"查看"下的"源文件"的时候,看到的将是上面的那段代码,而你真正的文件又躲过一劫。 

禁示另存为 
通过上面的两步好像你的源代码已经安全了,但别忘了,别人还可以将你的页面保存下来,再慢慢分析。不过别担心,下面我们来解决这个问题。 
在你要保密的网页中加入以下代码: 


<noscript><iframe src="/*.htm"></iframe></noscript> 


彻底屏蔽右键方法。


<body oncontextmenu="return false"> 


双击页面后自动滚屏,单击后停止。


<SCRIPT language=JavaScript> 
var currentpos,timer; 
function initialize() 
{ timer=setInterval("scrollwindow()",16); } 
function sc(){ 
clearInterval(timer); 
} 
function scrollwindow() 
{currentpos=document.body.scrollTop; 
window.scroll(0,++currentpos); 
if (currentpos != document.body.scrollTop) 
sc(); 
} 
document.onmousedown=sc 
document.ondblclick=initialize 
</script> 


设定脚本出错能继续运行


<script language="javascript"> 
function KillError() 
{ 
return false; 
} 
window.onerror=KillError; 
</script>
将彻底屏蔽鼠标右键

oncontextmenu="window.event.returnvalue=false" 


可用于Table 

<table border oncontextmenu=return(false)><td>no</table> 


取消选取、防止复制

<body onselectstart="return false"> 


不准粘贴 


onpaste="return false" 


防止复制


oncopy="return false;" oncut="return false;" 


IE地址栏前换成自己的图标 

<link rel="Shortcut Icon" href="favicon.ico"> 


可以在收藏夹中显示出你的图标 


<link rel="Bookmark" href="favicon.ico"> 


关闭输入法

<input style="ime-mode:disabled"> 


永远都会带着框架 


<script language="javascript"><!-- 
if (window == top)top.location.href = "frames.htm"; 
//frames.htm为框架网页 
// --> 
</script> 


防止被人frame 


<SCRIPT LANGUAGE=javascript><!-- 
if (top.location != self.location) 
top.location=self.location; 
// --> 
</SCRIPT>


转载:http://hi.baidu.com/sun%5Fgiser/blog/item/d5a322d8229f162411df9bad.html
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics