[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[原创] [分享]添加IE工具栏按钮及解除网页常见限制

  1. 'On Error Resume Next
  2. IEbarRegPath = "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\"
  3. '例1
  4. Guid = "{8287321c-032b-451d-b030-8fd617629efb}" 'Guid随便写,只要不和别的重名就可以了
  5. 'Guid = CreateObject("ScriptLet.TypeLib").Guid '可以用这个对象得到一个Guid
  6. RegPath = IEbarRegPath & Guid & "\" '按钮的注册表位置
  7. ButtonText = "执行JS" '按钮名称
  8. MenuText = "执行JS" '“工具”菜单中显示文字
  9. MenuStatusBar = "执行JS" '鼠标放在“工具”菜单相应条目上时状态栏显示文字
  10. ButtonType = "Script" '按钮类型,有4种:Exec(可执行文件)、Script(脚本)、ClsidExtension(COM对象)、BandCLSID(浏览器栏)
  11. FilePath = "C:\js.htm" '脚本文件路径
  12. Icon = "wscript.exe,1" '默认显示图标
  13. HotIcon = "wscript.exe,3" '鼠标放上去显示图标
  14. DefaultShow = "Yes" '按钮显示与否
  15. Call AddIEbar(RegPath, ButtonText, MenuText, MenuStatusBar, ButtonType, FilePath, Icon, HotIcon, DefaultShow)
  16. '例2
  17. Guid = "{8287321c-032b-451d-b030-8fd617629efc}" 'Guid随便写,只要不和别的重名就可以了
  18. 'Guid = CreateObject("ScriptLet.TypeLib").Guid '可以用这个对象得到一个Guid
  19. RegPath = IEbarRegPath & Guid & "\" '按钮的注册表位置
  20. ButtonText = "Explorer" '按钮名称
  21. MenuText = "资源管理器" '“工具”菜单中显示文字
  22. MenuStatusBar = "资源管理器" '鼠标放在按钮上时状态栏显示文字
  23. ButtonType = "Exec" '按钮类型,有4种:Exec(可执行文件)、Script(脚本)、ClsidExtension(COM对象)、BandCLSID(浏览器栏)
  24. FilePath = "C:\Windows\Explorer.exe" '可执行文件路径,可以是本地文件,也可以是网页地址
  25. Icon = "C:\Windows\Explorer.exe,0" '默认显示图标
  26. HotIcon = "C:\Windows\Explorer.exe,0" '鼠标放上去显示图标
  27. DefaultShow = "Yes" '按钮显示与否
  28. Call AddIEbar(RegPath, ButtonText, MenuText, MenuStatusBar, ButtonType, FilePath, Icon, HotIcon, DefaultShow)
  29. '设置了显示后,在“工具”菜单中可以看到相应条目,但系统还不会显示在工具栏上,得手动添加上去
  30. WScript.Echo "OK, 操作完成"
  31. '添加到IE工具栏按钮函数
  32. Function AddIEbar(RegPath, ButtonText, MenuText, MenuStatusBar, ButtonType, FilePath, Icon, HotIcon, DefaultShow)
  33.     dim clsid, ws
  34.     Select Case 0
  35.     Case StrComp(ButtonType,"Exec",1), StrComp(ButtonType,"Script",1), StrComp(ButtonType,"ClsidExtension",1)
  36.         clsid = "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}"
  37.     Case StrComp(ButtonType,"BandCLSID",1)
  38.         clsid = "{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}"
  39.     Case Else
  40.         'Err.Raise 10001, "Function 'AddIEbar'", "Argument 'ButtonType' error"
  41.         AddIEbar = false
  42.         exit function
  43.     End Select
  44.     Set ws = WScript.CreateObject("WScript.Shell")
  45.     ws.RegWrite RegPath & "CLSID", clsid, "REG_SZ"
  46.     ws.RegWrite RegPath & "ButtonText", ButtonText, "REG_SZ"
  47.     ws.RegWrite RegPath & "MenuText", MenuText, "REG_SZ"
  48.     ws.RegWrite RegPath & "MenuStatusBar", MenuStatusBar, "REG_SZ"
  49.     ws.RegWrite RegPath & ButtonType, FilePath, "REG_SZ"
  50.     ws.RegWrite RegPath & "Icon", Icon, "REG_SZ"
  51.     ws.RegWrite RegPath & "HotIcon", HotIcon, "REG_SZ"
  52.     ws.RegWrite RegPath & "Default Visible", DefaultShow, "REG_SZ"
  53.     set ws = nothing
  54. AddIEbar = true
  55. End Function
复制代码
C:\js.htm
  1. <script language="javascript">
  2. var win = window.external.menuArguments;
  3. var doc = win.document;
  4. function enableMouse()
  5. {
  6.     if (event != null)
  7.     {
  8.         event.returnValue = true;
  9.         event.cancelBubble = false;
  10.     }
  11.     return true;
  12. }
  13. function doEnableMouse(obj)
  14. {
  15.     obj.onmousedown = enableMouse;
  16.     obj.onmouseup = enableMouse;
  17.     obj.onmousemove = enableMouse;
  18.     obj.oncontextmenu = enableMouse;
  19.     obj.onselectstart = enableMouse;
  20.     obj.ondragstart = enableMouse;
  21.     obj.onbeforecopy = enableMouse;
  22.     obj.oncopy = enableMouse;
  23.     obj.onselect = enableMouse;
  24. }
  25. function doDocument(doc)
  26. {
  27. try
  28. {
  29.     doEnableMouse(doc);
  30.     doEnableMouse(doc.body);
  31.     var frs = doc.frames;
  32.     if (frs != null && frs.length>0)
  33.     {
  34.         for (var i=0; i < frs.length; i++)
  35.         {
  36.             doDocument(frs[i].document);
  37.         }
  38.     }
  39. } catch(e) {}
  40. }
  41. //解除鼠标右键限制
  42. doDocument(doc);
  43. //防止google搜索结果重定向
  44. if (win.location.href.search(/http:\/\/www\.google\.com\.hk/i) > -1)
  45. {
  46.     var el = doc.getElementById("RemoveGoogleRedirect");
  47.     if (!el)
  48.     {
  49.         var sc = doc.createElement("script");
  50.         sc.id = "RemoveGoogleRedirect";
  51.         sc.text = "function rwt(){return true;}";
  52.         doc.body.appendChild(sc);
  53.     }
  54. }
  55. var div = "<div id='zqz_tool' style='background-color:#d5d8de; background-image: url(about:blank); background-repeat: no-repeat; border-top: 1px solid #c0c3c9; bottom:0; left:0; width:100%; height:50px; line-height: 15px; padding: 0; margin: 0; font-size: 10px; text-align: center; overflow:visible; z-index:99999; position:fixed; /* for ie6 */ _position:absolute; ";
  56. var s = doc.documentElement.clientHeight ? true : false;
  57. if (s) div += "_top: expression(documentElement.scrollTop + documentElement.clientHeight - this.offsetHeight); ";
  58. else div += "_top: expression(body.scrollTop + body.clientHeight - this.offsetHeight); ";
  59. div += "'>";
  60. div += "<div style='cursor: hand; border-bottom: 1px solid #a0a3a9; color: blue; height:10px; line-height: 10px; padding: 0; margin: 0; ' onclick=(function(o){if(o.parentNode.style.height!='10px'){o.parentNode.style.height='10px';o.parentNode.style.overflow='hidden';o.innerText='▲';}else{o.parentNode.style.height='50px';o.parentNode.style.overflow='visible';o.innerText='▼';}})(this)>▼</div>";
  61. div +="<textarea id='zqz_cmd' rows=2 cols=80>new ActiveXObject('WScript.Shell').Run('calc');</textarea><button onclick='eval(zqz_cmd.innerText)'>eval</button>";
  62. div +="<input id='zqz_external' type='checkbox' title='选中后再次点击工具栏按钮执行此代码' />外部";
  63. div += '</div>';
  64. doc.getElementById('zqz_tool') || doc.body.insertAdjacentHTML("beforeEnd", div);
  65. s = doc.getElementById('zqz_external');
  66. s && s.checked && eval( doc.getElementById('zqz_cmd').value );
  67. //new ActiveXObject('WScript.Shell').Run('calc');
  68. //eval(clipboardData.getData('text'));
  69. </script>
复制代码
1

评分人数

    • broly: 支持原创技术 + 1

那天弄电脑的用for语句和regsvr32重新注册了系统所有组件,我没看清,请问如何实现?

TOP

网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQDownload 702; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
时间戳: Sat, 12 Nov 2011 14:21:08 UTC


消息: 'win.document' 为空或不是对象
行: 3
字符: 1
代码: 0
URI: file:///C:/Users/Broly/Desktop/js.htm

JS.HTM有点错误,IE8
---学无止境---

TOP

返回列表