欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

新手入门常用代码集锦

时间:2021-01-09 11:15:54|栏目: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>
■页面设置■
<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=后退>

上一篇:json字符串传到前台input的方法

栏    目:JavaScript代码

下一篇:网页挂马方式整理及详细介绍

本文标题:新手入门常用代码集锦

本文地址:http://www.codeinn.net/misctech/42807.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有