JavaScript使用技术集合

JavaScript使用技术集合

1、打开一个窗体

window.open ("Default3.aspx", "newwindow", "height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no"); 

 参数解释:

  "page.html" 弹出窗口的文件名;

  "newwindow" 弹出窗口的名字(不是文件名),非必须,可用空"代替;

  height=100 窗口高度;

  width=400 窗口宽度;

  top=0 窗口距离屏幕上方的象素值;

  left=0 窗口距离屏幕左侧的象素值;

  toolbar=no 是否显示工具栏,yes为显示;

  menubar,scrollbars 表示菜单栏和滚动栏。

  resizable=no 是否允许改变窗口大小,yes为允许;

  location=no 是否显示地址栏,yes为允许;

  status=no 是否显示状态栏内的信息(通常是文件已?打开),yes为允许;

2、定时关闭窗口

< script language="JavaScript">

  function closeit() {

  setTimeout("self.close()",10000) //毫秒

  }

  < /script>

(说明:如果是本窗口,窗口时系统会给出提示;而是弹出窗口的话,将直接关闭)

3、实现弹出窗口提示,又防止刷新被重复提交的方法

Response.Write("<script language='JavaScript'>alert('弹出窗口!');window.location='a.aspx';</script>");

(说明:a.aspx为该窗口)

4、更改完后,刷新主窗口的方法

    if(opener) opener.location.reload();

Response.Write("<script>window.opener.location.href=window.opener.location.href;</script>");

5、捕捉回车键

    <script   language="javascript"   event="onkeydown"   for="document">  
  if(event.keyCode==13)  
  {   

document.all('ctl00$ContentPlaceHolder1$btn_login').focus();
  document.all('ctl00$ContentPlaceHolder1$btn_login').click();  
  }  
  </script>   

6、打印窗口[<a href="javascript:window.print()">打印资料</a>]

7、将子窗口内容传到父窗口       

window.opener.parent.document.form1.Text1.value = document.form1.Text1.value;

8、屏蔽鼠标右键

在body标签里加上οncοntextmenu=self.event.returnvalue=false

或者

<script language="javascript">
<!--
function document.oncontextmenu()
{
  return false;
}
-->
</script>

function nocontextmenu()
{
    if(document.all) {
        event.cancelBubble=true;
        event.returnvalue=false;
        return false;
    }
}

或者

<body οnmοusedοwn="rclick()" οncοntextmenu= "nocontextmenu()">

<script language="javascript">
<!--
function rclick()
{
    if(document.all) {
        if (event.button == 2){
            event.returnvalue=false;
        }
    }
}
-->
</script>

9、屏蔽 Ctrl+N、Shift+F10、F5刷新、退格键

<script language="javascript">
<!--
  //屏蔽鼠标右键、Ctrl+N、Shift+F10、F5刷新、退格键
function window.onhelp(){return false} //屏蔽F1帮助
function KeyDown(){
  if ((window.event.altKey)&&
      ((window.event.keyCode==37)||   //屏蔽 Alt+ 方向键 ←
       (window.event.keyCode==39))){  //屏蔽 Alt+ 方向键 →
     alert("不准你使用ALT+方向键前进或后退网页!");
     event.returnvalue=false;
     }

     /* 注:这还不是真正地屏蔽 Alt+ 方向键,
     因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放,
     用鼠标点掉警告框,这种屏蔽方法就失效了。以后若
     有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/

  if ((event.keyCode == 8) &&
      (event.srcElement.type != "text" &&
      event.srcElement.type != "textarea" &&
      event.srcElement.type != "password") ||           //屏蔽退格删除键  
      (event.keyCode==116)||                            //屏蔽 F5 刷新键
      (event.ctrlKey && event.keyCode==82)){            //Ctrl + R
     event.keyCode=0;
     event.returnvalue=false;
     }
  if ((event.ctrlKey)&&(event.keyCode==78))   //屏蔽 Ctrl+n
     event.returnvalue=false;
  if ((event.shiftKey)&&(event.keyCode==121)) //屏蔽 shift+F10
     event.returnvalue=false;
  if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
      window.event.returnvalue = false;  //屏蔽 shift 加鼠标左键新开一网页
  if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4
      window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
      return false;}
  }
 /* 另外可以用 window.open 的方法屏蔽 IE 的所有菜单
第一种方法:
  window.open("你的.htm", "","toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=no,top=0,left=0")
第二种方法是打开一个全屏的页面:
  window.open("你的.asp", "", "fullscreen=yes")
 */
//-->
</script>

10、屏蔽浏览器右上角“最小化”“最大化”“关闭”键

<script language=javascript>
function window.onbeforeunload()
{
  if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
  {
    window.event.returnvalue = "";
  }
}
</script>

或者使用全屏打开页面

<script language="javascript">
<!--
window.open(www.32pic.com,"32pic","fullscreen=3,height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
-->
</script>

注:在body标签里加上οnbefοreunlοad="javascript:return false"(使不能关闭窗口)

11、屏蔽F5键


<script language="javascript">
<!--
function document.onkeydown()
{
    if ( event.keyCode==116)
    {
        event.keyCode = 0;
        event.cancelBubble = true;
        return false;
    }
}
-->
</script>

12、屏蔽IE后退按钮 在你链接的时候用 <a href="javascript:location.replace(url)">

13、屏蔽主窗口滚动条在body标签里加上 style="overflow-y:hidden"

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

在body标签里加上οnlοad="setInterval('clipboardData.setData(/'Text/',/'/')',100)"

19、屏蔽网站的打印功能

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

20、判断IE是否开启COOKIE

<script type="text/javascript">

      
function CookieEnable()
      {
        
var result=false;
        
if(navigator.cookiesEnabled)
          
return true;
        document.cookie = "testcookie=yes;";
        
var cookieSet = document.cookie;
        
if (cookieSet.indexOf("testcookie=yes") > -1)
          result=
true;
        document.cookie = "";
        
return result;
      }

      
if(!CookieEnable())
      {
        alert("
对不起,您的浏览器的Cookie功能被禁用,请开启");
      }
</script>

21、在规定时间内跳转

<META http-equiv=V="REFRESH" content="5;URL=http://www.51js.com"> 

22、ENTER键可以让光标移到下一个输入框

<input οnkeydοwn="if(event.keyCode==13)event.keyCode=9">

23、设定打开页面的大小及位置
<body οnlοad="top.resizeTo(300,200);">
<body οnlοad="top.moveBy(300,200);">
24、将文本框变为线条

 

<input id="abc" type=text style="border-left:none; border-right:none; border-top:none; border-bottom: 
1 solid #000000"/>

25、 屏蔽功能键 Shift,Alt,Ctrl
<script>
function look(){ 
if(event.shiftKey) 
alert("
禁止按 Shift !"); // 可以换成 ALT   CTRL

document.οnkeydοwn=look; 
</script>

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

27、不准粘贴 οnpaste="return false"

29、 防止复制οncοpy="return false;" oncut="return false;"

30、彻底屏蔽鼠标右键οncοntextmenu="window.event.returnValue=false"

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

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

33、11种刷新按钮的方法

<input type=button value=刷新 οnclick="history.go(0)">
<input type=button value=刷新 οnclick="location.reload()">
<input type=button value=刷新 οnclick="location=location">
<input type=button value=刷新 οnclick="location.assign(location)">
<input type=button value=刷新 οnclick="document.execCommand('Refresh')">
<input type=button value=刷新 οnclick="window.navigate(location)">
<input type=button value=刷新 οnclick="location.replace(location)">
<input type=button value=刷新 οnclick="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=刷新 οnclick="a1.click()">

34、如何使用javascript在html中获取url参数

<script type="text/javascript">
function $G(){
var Url=top.window.location.href;
var u,g,StrBack='';
if(arguments[arguments.length-1]=="#")
   u=Url.split("#");
else
   u=Url.split("?");
if (u.length==1) g='';
else g=u[1];

if(g!=''){
   gg=g.split("&");
   var MaxI=gg.length;
   str = arguments[0]+"=";
   for(i=0;i<MaxI;i++){
      if(gg[i].indexOf(str)==0) {
        StrBack=gg[i].replace(str,"");
        break;
      }
   }
}
return StrBack;
}
</script>

上边个函数可以放在外部js文件、head、body等未知皆可
使用参考:
例:想获取URL http://fhuang.com/?ip=202.201.0.137 中IP这个参数的内容
<script type="text/javascript">
var IP=$G("IP")
//之后你可以将IP用来alert、write等,总之可以最为一个变量随便使用了
</script>

35加入收藏夹的代码

<a href=# onClick=window.external.addFavorite(http://bbs.055.cn';.'拂晓雅阁') target=_self title=拂晓雅阁>加入收藏夹</a>

36设为首页

<script language=javascript>
<!--
function defaul_home(){
this.home.style.behavior='url(#default#homepage)';this.home.setHomePage(http://bbs.055.cn/';
}
var focusok=false;
if (navigator.appName == Netscape{
focusok=true;
}
vers=navigator.appVersion;
if (navigator.appName == Microsoft Internet Explorer{
pos=vers.lastIndexOf('.');
vers=vers.substring(pos-1,vers.length);
}
proper_version=parseFloat(vers);

if(proper_version>=5){
focusok=true;
}
function launchstock1(htmlurl){
var stock=window.open(htmlurl,stock,top=2,left=2,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,
resizable=no,width=700,height=510;
if(focusok){
stock.focus();
}
return true;
}
function launchstock(){
var stock=window.open(,stock,top=2,left=2,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,

resizable=no,width=700,height=510;
if(focusok){
stock.focus();
}
return true;
}
// -->
</script>
<a href=# name=home onClick=defaul_home(); title===E代时光==>设为首页</a>

37最小化、最大化、关闭窗口
<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=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>

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

39各种样式的光标  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

40页面自动跳转
<script language="javascript">
        m=5

Time=window.setInterval("Alors()",1000);
function Alors(){
             Ob=document.all("L");
                         Ob.innerHTML=m;
                         m--;
                         if(m==0){
                           window.open('Send.aspx','_self');
                         }

}
</script>

 

wan
<script language="javascript" type="text/javascript"> </script>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值