日期:2014-05-16  浏览次数:20274 次

js 操作浏览器的各种功能
1,js操作剪贴板
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>标题页</title>
    <script language="javascript">
     function windowCopy(){
     window.clipboardData.setData("Text",txt1.innerText);  
     }
     function windowParse(){
     var txt= window.clipboardData.getData("Text");  
     txt1.innerText=txt+"粘贴完毕"
     }
    </script>
</head>
<body>
<textarea cols=30 rows=10 id="txt1">
</textarea>
<table id="mytbl" width="300" height="50" border="0" cellspacing="2" cellpadding="0" bgcolor="#FFb609">
  <tr> 
    <td> <input id="Button1" type="button" value="window剪贴板-剪切" onclick="windowCopy()" /></td>
    <td> <input id="Button1" type="button" value="window剪贴板-粘贴" onclick="windowParse()" /></td>
  </tr>
</table>
</body>
</html>

2,js打开硬盘驱动器
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
</head>
<body>
<form action="file:///c|/"><input type="submit" value="打开C盘"></form>
<form action="file:///d|/"><input type="submit" value="打开D盘"></form>
<form action="file:///e|/"><input type="submit" value="打开E盘"></form>
</body>
</html>

3,js 加入收藏夹
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
</head>
<body>
<span style="CURSOR: hand" onClick="window.external.addFavorite('http://www.google.com','最爱的搜索')" title="Google搜索">收藏搜索网站</span>
</body>
</html>


4,js 复制网址和标题
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>标题页</title>
</head>
<body>
<input type="button" name="Submit" onClick='toClipBoard()' value="复制网址,传给好友"> 
<script language="javascript"> 
function toClipBoard()
{ 
var clipBoardContent=""; 
clipBoardContent+=document.title;     //获取页面标题
clipBoardContent+="\n"; 
clipBoardContent+=this.location.href; //获取页面地址 
//将拷贝内容存放到剪贴板中
window.clipboardData.setData("Text",clipBoardContent); 
alert("复制成功,可以粘贴到你的QQ/MSN上,推荐给你的好友!"); 
} 
</script>
</body>
</html>


5,js 关闭输入法
<input id="txtname" style="ime-mode:disabled"> 

6,js 获取浏览器版本信息
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
<script language="JavaScript">
    document.write("浏览器名称: "+navigator.appName+"<br>");
    document.write("浏览器版本号: "+navigator.appVersion+"<br>");
    document.write("系统语言: "+navigator.systemLanguage+"<br>");
    document.write("系统平台: "+navigator.platform+"<br>");
    document.write("浏览器是否支持cookie: "+navigator.cookieEnabled+"<br>");
</script>
</head>
<body  >
<div>以上是浏览器的检测信息/div>
</body>
</html>


7,js 显示本地计算机信息
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
<script language="javascript">
    var WshNetwork = new ActiveXObject("WScript.Network"); //创建
    alert("用户域:  " + WshNetwork.UserDomain);           //显示用户所在的域
    alert("计算机名称:  " + WshNetwork.ComputerName);     //显示计算机名
    alert("用户名:  " + WshNetwork.UserName);             //显示登录用户名
</script>
</head>
<body >
</body>
</html>

8,ie 文件菜单中的打开命令,和选项命令
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
</head>
<body>
<a href="#" onclick=document.execCommand("open")>打开</a>
<a href="#" onclick=window.external.showBrowserUI