常用JS代码(一)

来源:互联网 发布:青铜器乐队知乎 编辑:程序博客网 时间:2024/05/16 09:21
 

javaScript 应用

1.       退出/删除应用  confirm(”message”);

<TD ><A id=ctl00 onclick="return confirm('确定要删除吗?');"  href="www.sina.com">删除</A> </TD>

function confirmCleanUp() {
   if (confirm("Are you sure you want to quit this application?")) {
      cleanUp()
   }
} You can call the confirmCleanUp function in the onClick event handler of a form's push button, as shown in the following example:

<INPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()">

2.       History 向前/向后Window.forward,History.back(),window.go();

方法概览

back

Loads the previous URL in the history list.

forward

Loads the next URL in the history list.

go

Loads a URL from the history list.

示例:

 

 

 

网页颜色自由切换

<TR>

          <TD><SPAN>选按不同颜色按键以测试前景颜色效果 <FONT color=#ff0000>(只适合 Internet

            Explorer)</FONT> </SPAN>

            <FORM><SPAN><INPUT onclick="document.fgColor='#0000FF'" type=button value=BLUE name=colr>

            &nbsp; <INPUT onclick="document.fgColor='#FF0000'" type=button value=RED name=colr2>

            &nbsp; <INPUT onclick="document.fgColor='#FFFFFF'" type=button value=WHITE name=colr2>

            &nbsp; <INPUT onclick="document.fgColor='#00FF00'" type=button value=GREEN name=colr2>

            &nbsp; <INPUT onclick="document.fgColor='#c6a06d'" type=button value=TAN name=colr2>

            &nbsp; <INPUT onclick="document.fgColor='#FFFF00'" type=button value=YELLOW name=colr2>

            &nbsp; <INPUT onclick="document.fgColor='#000000'" type=button value=BLACK name=colr2>

            </SPAN></FORM><SPAN>选按不同颜色按键以测试背景颜色效果 </SPAN>

            <FORM><SPAN><INPUT onclick="document.bgColor='#0000FF'" type=button value=BLUE name=colr2>

            &nbsp; <INPUT onclick="document.bgColor='#FF0000'" type=button value=RED name=colr2>

            &nbsp; <INPUT onclick="document.bgColor='#FFFFFF'" type=button value=WHITE name=colr2>

            &nbsp; <INPUT onclick="document.bgColor='#00FF00'" type=button value=GREEN name=colr2>

            &nbsp; <INPUT onclick="document.bgColor='#c6a06d'" type=button value=TAN name=colr2>

            &nbsp; <INPUT onclick="document.bgColor='#FFFF00'" type=button value=YELLOW name=colr2>

            &nbsp; <INPUT onclick="document.bgColor='#000000'" type=button value=BLACK name=colr2>

            </SPAN></FORM>

            <CENTER><SPAN>或输入一个 RGB 颜色码或名称</SPAN> </CENTER>

            <FORM method=post>

            <CENTER><SPAN>&nbsp; <INPUT maxLength=30 onchange=Set(this) size=12

            name=Fdadsage> &nbsp; <INPUT onclick=Variable(this.form) type=button value=输入背景色 name=BUTTON>

            </SPAN></CENTER></FORM></TD></TR></TABLE></CENTER></TD></TR>

 

 

 

javascript无提示关闭窗口,兼容IE,Firefox

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无提关闭窗</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function Close()
{  
   //关闭当前窗口
   window.open('','_parent','');
   window.close();
}
function OpenWin(url)
{
   //全屏打开窗口,网址 url
    window.open(url,'_blank','fullscreen=1');
    Close();
}
</script>
<input type="button" value="关闭"   onclick="Close();"/>
</body>
</html>

 

方法一:

此方法在IE7中测试通过。

 

 

 

 

 

方法二:

1·把下面这段代码加到你要执行关闭IE窗口的那桢上:
   getURL("javascript:window.opener=null;window.close();");

2·把下面的代码加到你的那个按钮上:
on(release){
    getURL("javascript:window.opener=null;window.close();");
}
方法三:
在不是js打开的页面上按window.close(),会有提示框,很烦,现在可以不用了,没有提示框直接关闭窗口。
试试下面代码:
<object id=WebBrowser width=0 height=0 classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2>
</object>
<input type=button name=Button value=关闭窗口 onClick=document.all.WebBrowser.ExecWB(45,1)>

试着改变参数会得到其他一些功能:
WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示

这些只对IE5.5以上版本有效,我是在IE6下测试的,通过的。

 

原创粉丝点击