`
learnmore
  • 浏览: 597276 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

javascript 操作页面

阅读更多
一些JavaScript代码
[日期:2004-11-10] 来源:  作者: [字体:大 中 小] 

<!--

1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table

2. <body onselectstart="return false"> 取消选取、防止复制 

3. onpaste="return false" 不准粘贴

4. oncopy="return false;" oncut="return false;" 防止复制

5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标

6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标

7. <input style="ime-mode:disabled"> 关闭输入法

8. 永远都会带着框架
<script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>

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

10. <noscript><iframe src=*.html></iframe></noscript> 网页将不能被另存为

11. <input type=button value=查看网页源代码
onclick="window.location = 'view-source:'+ ''">

12. 一段JavaScript的关机代码

win98/me
<script language="JavaScript">
var wsh = new ActiveXObject("WScript.Shell");
wsh.Run("rundll32.exe user.exe,exitWindows");
</script>

win2000 or xp
<script language="JavaScript">
var wsh = new ActiveXObject("WScript.Shell");
wsh.sendKeys("^{ESC}");
wsh.sendKeys("{UP}~S~");
</script>

13. 取得控件的绝对位置

//Javascript
<script language="Javascript">
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"\nleft="+l);
}
</script>

//VBScript
<script language="VBScript"><!--
function getIE()
dim t,l,a,b
set a=document.all.img1
t=document.all.img1.offsetTop
l=document.all.img1.offsetLeft
while a.tagName<>"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
--></script>

14. 光标是停在文本框文字的最后
<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart('character',e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">

15. 调用客户端的程序
<script>
var wsh=new ActiveXObject("wscript.shell")
wsh.run("notepad.exe")
</script>

16. 最小化、最大化、关闭窗口
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-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()>
本例适用于IE

17. 屏蔽 Alt+F4
<script language=Javascript>
function document.onkeydown()
{
if ((window.event.altKey)&&(window.event.keyCode==115)){
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
return false;}
}
</script>

18. 自己动手为string添加Trim
<script language=Javascript>
String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
String.prototype.Ltrim = function(){return this.replace(/(^\s*)/g, "");}
String.prototype.Rtrim = function(){return this.replace(/(\s*$)/g, "");}
var str = " abc de ";
alert(str.Trim());
</script>

19. 检查一段字符串是否全由数字组成
<script language="Javascript"><!--
function checkNum(str){return str.match(/\D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>

20. 获得一个窗口的大小
document.body.clientWidth,document.body.clientHeight

21. 怎么判断是否是字符
if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");

22.TEXTAREA自适应文字行数的多少
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
</textarea>

23. 日期减去天数等于第二个日期
<script language=Javascript>
function cc(dd,dadd)
{
//可以加上错误处理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script>

24. 选择了哪一个Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>Style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<INPUT type="button" value="check" onclick="checkme()">
</BODY></HTML>

25.获得本页url的request.servervariables("")集合
Response.Write "<TABLE border=1><!-- Table Header --><TR><TD><B>Variables</B></TD><TD><B>Value</B></TD></TR>"
for each ob in Request.ServerVariables
Response.Write "<TR><TD>"&ob&"</TD><TD>"&Request.ServerVariables(ob)&"</TD></TR>"
next
Response.Write "</TABLE>"

26.
本机ip<%=request.servervariables("remote_addr")%>
服务器名<%=Request.ServerVariables("SERVER_NAME")%>
服务器IP<%=Request.ServerVariables("LOCAL_ADDR")%>
服务器端口<%=Request.ServerVariables("SERVER_PORT")%>
服务器时间<%=now%>
IIS版本<%=Request.ServerVariables"SERVER_SOFTWARE")%>
脚本超时时间<%=Server.ScriptTimeout%>
本文件路径<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%>
服务器CPU数量<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%>
服务器解译引擎<%=ScriptEngine & "/"& ScriptEngineMajorVersion &"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %>
服务器操作系统<%=Request.ServerVariables("OS")%>

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

28. 检测某个网站的链接速度:
把如下代码加入<body>区域中:
<script language=Javascript>
tim=1
setInterval("tim++",100)
b=1

var autourl=new Array()
autourl[1]="http://www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="http://www.sina.com.cn"
autourl[4]="http://www.nuaa.edu.cn"
autourl[5]="http://www.cctv.com"

function butt(){
document.write("<form name=autof>")
for(var i=1;i<autourl.length;i++)
document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO onclick=window.open(this.form.url"+i+".value)><br/>")
document.write("<input type=submit value=刷新></form>")
}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="链接超时"}
else
{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}
b++
}
function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl[i]+"/"+Math.random +".length;i++)document.write("<img src=http://"+autourl[i]+"/"+Math.random()+" width=1 height=1 onerror=auto('http://"+autourl[i]+"')>")}
run()</script>

29. 各种样式的光标
auto :标准光标
default :标准箭头
hand :手形光标
wait :等待光标
text :I形光标
vertical-text :水平I形光标
no-drop :不可拖动光标
not-allowed :无效光标
help :?帮助光标
all-scroll :三角方向标
move :移动标
crosshair :十字标
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize

30.实现另存为:
<input type=button value=保存 onclick=document.execCommand('SaveAs')>

31.窗口最大化(全屏显示不带工具栏等):
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</head>
<input type=button value=最大化 onclick="javascript:new ActiveXObject('wscript.shell').sendKeys('{F11}')">
</BODY>
</HTML>


32.

<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>
</OBJECT>
<input onclick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开 name=Button1>
<input onclick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为 name=Button2>
<input onclick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性 name=Button3>
<input onclick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印 name=Button>
<input onclick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置 name=Button4>
<br/>
<input onclick=window.location.reload() type=button value=刷新 name=refresh>
<input onclick="window.external.ImportExportFavorites(true,'');" type=button value=导入收藏夹 name=Button5>
<input onclick="window.external.ImportExportFavorites(false,'');" type=button value=导出收藏夹 name=Button32>
<input onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹 name=Button22>
<br/>
<input onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)" type=button value=整理收藏夹 name=Submit2>
<input onclick='window.location="view-source:" + window.location.href' type=button value=查看源文件 name=Button7>
<input onclick="window.external.ShowBrowserUI('LanguageDialog', null)" type=button value=语言设置 name=Button6>
<input onclick=history.go(1) type=submit value=前进 name=Submit>
<input onclick=history.go(-1) type=submit value=后退 name=Submit2>
要完成此效果把如下代码加入到<body>区域中

<input type="button" name="Button" value="点击保存页面" onClick="document.all.WebBrowser.ExecWB(4,1)">
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
………………………………………………………………………………………………………………………………
鼠标自定义
<script language=javascript>var Loaded=false;var Flag=false;</script>
<script src='http://files.cometsystems.com/&#106avascript/lc2000.js'
language=javascript></script>
<script language=javascript>if(Loaded&&Flag)TheCometCursor('cd_electric',0,626);</script>


要完成此效果把如下代码加入到<head>区域中

<SCRIPT LANGUAGE="javascript">
<!-- Begin
var x, y, xold, yold, xdiff, ydiff;
var dir = Array();
dir[0] = "n-resize";
dir[1]="ne-resize";
dir[2]="e-resize";
dir[3]="se-resize";
dir[4] = "s-resize";
dir[5]="sw-resize";
dir[6]="w-resize";
dir[7]="nw-resize";
document.onmousemove = FindXY;
function display(direction) {
document.body.style.cursor = dir[direction];
}
function FindXY(loc) {
x = (document.layers) ? loc.pageX : event.clientX;
y = (document.layers) ? loc.pageY : event.clientY;
xdiff = x - xold;
ydiff = y - yold
if ((xdiff < 2) && (ydiff < -2)) display(0);
if ((xdiff < 2) && (ydiff > 2)) display(4);
if ((xdiff > 2) && (ydiff < 2)) display(2);
if ((xdiff < -2) && (ydiff < 2)) display(6);
if ((xdiff > 2) && (ydiff > 2)) display(3);
if ((xdiff > 2) && (ydiff < -2)) display(1);
if ((xdiff < -2) && (ydiff > 2)) display(5);
if ((xdiff < -2) && (ydiff < -2)) display(7);
xold = x;
yold = y;
}
// End -->
</script>

<input type=button value=剪切 onclick=document.execCommand('Cut')>
<input type=button value=拷贝 onclick=document.execCommand('Copy')>
<input type=button value=粘贴 onclick=document.execCommand('Paste')>
<input type=button value=撤消 onclick=document.execCommand('Undo')>
<input type=button value=删除 onclick=document.execCommand('Delete')>
<input type=button value=黑体 onclick=document.execCommand('Bold')>
<input type=button value=斜体 onclick=document.execCommand('Italic')>
<input type=button value=下划线 onclick=document.execCommand('Underline')>
<input type=button value=停止 onclick=document.execCommand('stop')>
<input type=button value=保存 onclick=document.execCommand('SaveAs')>
<input type=button value=另存为 onclick=document.execCommand('Saveas',false,'c:\\test.htm')>
<input type=button value=字体 onclick=document.execCommand('FontName',false,fn)>
<input type=button value=字体大小 onclick=document.execCommand('FontSize',false,fs)>
<input type=button value=刷新 onclick=document.execCommand('refresh',false,0)>

<input type=button value=刷新 onclick=window.location.reload()>
<input type=button value=前进 onclick=history.go(1)>
<input type=button value=后退 onclick=history.go(-1)>
<input type=button value=前进 onclick=history.forward()>
<input type=button value=后退 onclick=history.back()>

<input type=button value=导入收藏夹 onclick=window.external.ImportExportFavorites(true,"http://localhost" ;>
<input type=button value=导出收藏夹 onclick=window.external.ImportExportFavorites(false,"http://localhost" ;>
<input type=button value=整理收藏夹 onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
<input type=button value=查看源文件 onclick="window.location = 'view-source:'+ window.location.href">
<input type=button value=语言设置 onclick="window.external.ShowBrowserUI('LanguageDialog', null)">
<input type=button value=加入收藏夹 onclick="window.external.AddFavorite(','')">
<input type=button value=加入到频道 onclick="window.external.addChannel('' ">
<input type=button value=设成主页 onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('' ">

<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
<input type=button value=打开 onclick=document.all.WebBrowser.ExecWB(1,1)>
<input type=button value=另存为 onclick=document.all.WebBrowser.ExecWB(4,1)>
<input type=button value=全选 onclick=document.all.WebBrowser.ExecWB(17,1)>
<input type=button value=属性 onclick=document.all.WebBrowser.ExecWB(10,1)>
<input type=button value=关闭窗口 onclick=document.all.WebBrowser.ExecWB(45,1)>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>



<body><SCRIPT LANGUAGE="JavaScript">
var s = "网页正文部分宽:"+ document.body.clientWidth;
s += "\r\n网页正文部分高:"+ document.body.clientHeight;
s += "\r\n网页正文部分上:"+ window.screenTop;
s += "\r\n网页正文部分左:"+ window.screenLeft;
s += "\r\n屏幕分辨率的高:"+ window.screen.height;
s += "\r\n屏幕分辨率的宽:"+ window.screen.width;
s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;
s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;
alert(s);
</SCRIPT>


33.取下拉菜单的值
document.all("listbox1").options[document.all("listbox1").selectedIndex].value
document.all("listbox1").options[document.all("listbox1").selectedIndex].text


34.如何用js把网页中的数据导入excel

<script type="text/javascript">
function AllAreaExcel() {
  var oXL = new ActiveXObject("Excel.Application");
  var oWB = oXL.Workbooks.Add();
  var oSheet = oWB.ActiveSheet; 
  var sel=document.body.createTextRange();
  sel.moveToElementText(PrintA);
  sel.select();
  sel.execCommand("Copy");
  oSheet.Paste();
  oXL.Visible = true;
}
</script>

这段js的意思是说,把table id名称为PrintA的数据导入一个新打开的excel中
-->

分享到:
评论

相关推荐

    JavaScript动态页面制作

    "JavaScript动态页面制作"是现代Web开发中不可或缺的一部分,它涵盖了多个关键知识点,包括DOM操作、事件处理、AJAX异步通信以及动画效果实现等。 1. DOM(Document Object Model)操作:DOM是HTML和XML文档的结构...

    JAVASCRIPT页面效果实例

    在“JAVASCRIPT页面效果实例”中,我们可以深入探讨如何使用JavaScript来增强用户体验并创建引人入胜的网页效果。下面将详细介绍几个关键的JavaScript页面效果及其实现方法。 1. **页面加载动画** 当用户访问网站...

    100个Javascript特效页面以及源代码

    1. **DOM操作**:JavaScript通过Document Object Model(DOM)来操作HTML元素,改变页面内容、样式或结构。这些特效可能涉及到元素的选择、添加、删除、属性修改等操作。 2. **事件处理**:JavaScript可以响应用户...

    Javascript 增强页面效果第二章项目训练

    在JavaScript的世界里,增强页面效果是一项关键技能,它能让用户与网页有更丰富的交互体验。在"Javascript 增强页面效果第二章项目训练"中,我们将深入探讨如何利用JavaScript来提升网页的视觉表现和用户体验。这个...

    Calculator Using JavaScript .zip

    DOM是一个表示HTML或XML文档的API,允许JavaScript操作页面上的元素。例如,JavaScript可以找到特定的HTML元素,更改其内容、样式或属性,或者监听和响应用户的交互。在这个计算器中,JavaScript可能会选择或创建DOM...

    javascript操作元素的常见方法小结

    本文将结合实例,对JavaScript操作页面元素的常见方法进行小结。 首先,获取页面元素是进行其它操作的前提。document 对象提供了几个常用的方法来获取页面元素。例如,`getElementById` 方法可以获取页面上具有唯一...

    javascript页面特效

    在这个主题“javascript页面特效”中,我们将深入探讨JavaScript如何被用来创建各种令人惊叹的页面效果。 首先,JavaScript的核心在于DOM(Document Object Model)操作。DOM是HTML和XML文档的结构化表示,通过...

    JavaScript权威指南(原书第5版)源代码

    源代码会教你如何使用JavaScript操作页面元素和处理事件。 9. Ajax:异步JavaScript和XML,用于在不刷新整个页面的情况下更新部分内容,源代码可能包含XMLHttpRequest或fetch API的使用示例。 10. 闭包:...

    JavaScript各种页面特效

    以上各特效的应用,需要开发者具备基本的JavaScript知识,包括DOM操作、事件处理、定时器、动画原理等。通过学习和实践这些特效,不仅可以提升网页的视觉效果,还能提高编程技巧和用户体验设计能力。同时,利用现成...

    购物车 静态页面 含javascript

    在构建一个购物网站时,购物车页面是必不可少的组成部分,它允许用户查看所选商品、调整数量、计算总价以及进行结账操作。本项目“购物车静态页面含JavaScript”就是一个专注于实现这些功能的示例。这个页面是静态的...

    JavaScript客户端验证和页面特效制作(JavaScript)

    本文将深入探讨JavaScript客户端验证和页面特效制作的核心知识点。 **一、JavaScript客户端验证** 客户端验证是在用户提交表单之前,通过JavaScript在用户浏览器端进行的数据检查。这有助于提高用户体验,减少...

    超酷的javaScript页面特效合集

    JavaScript是一种强大的客户端脚本语言,广泛应用于网页和网络应用开发,尤其在实现页面动态效果和交互性方面表现出色。这个“超酷的JavaScript页面特效合集”无疑为开发者提供了丰富的资源,帮助他们创造出引人入胜...

    很炫的JavaScript效果页面

    在网页上,JavaScript可以监听用户的鼠标点击、键盘输入等事件,然后根据这些事件执行相应的操作,如改变页面内容、弹出对话框、加载新的数据等。这种动态交互使得网页更具活力,提高了用户体验。 其次,JavaScript...

    javascript客户端验证和页面特效制作项目案例

    JavaScript是Web开发中不可或缺的一部分,尤其在客户端验证和页面特效制作方面发挥着重要作用。这个"javascript客户端验证和页面特效制作项目案例"旨在帮助学习者掌握JavaScript的核心概念,并将其应用于实际项目中...

    javascript页面导航特效

    JavaScript 页面导航特效是一种常见的网页设计技术,用于提升用户体验和网站的互动性。在这个主题中,我们将深入探讨如何利用 JavaScript 实现动态、引人入胜的导航菜单,以及它与 HTML 和 CSS 的配合。 首先,"一...

    JavaScript客户端验证和页面特效制作.jar

    在"JavaScript客户端验证和页面特效制作.jar"这个资源中,我们可以推测它可能包含了一系列关于JavaScript学习的章节或教程,尤其是侧重于这两方面的内容。"chapter1"可能是系列教程的第一部分,可能涵盖了基础的...

    javascript页面动态效果

    综上所述,JavaScript页面动态效果是Web开发中不可或缺的一部分,它涉及到DOM操作、事件处理、动画、异步通信等多个方面,通过学习和掌握这些知识点,开发者可以创建出更加生动、富有吸引力的网页。

    javascript页面加载完执行事件代码

    在当今互联网应用开发中,JavaScript作为前端开发的核心技术之一,承担着页面交互、动态效果、数据处理等多项关键任务。掌握页面加载完毕后执行JavaScript代码的方法对于开发者来说至关重要。本文将深入探讨如何在...

Global site tag (gtag.js) - Google Analytics