首页 > 代码库 > VBA的inputBox函数的JScript模拟

VBA的inputBox函数的JScript模拟


本文要点:

  1. 示例WScript.CreateObject的事件前缀绑定事件处理过程
  2. 示例InternetExplorer.Application在JScript下来模仿inputBox函数
  3. 示例JScript脚本宿主运行时访问页面内容、脚本的方法。

估计这文章一发表就注定被转抄的命运了,标记一下源地址:http://blog.csdn.net/winsenjiansbomber/article/details/41338243

/* Tips: an alert emulator for Wscript host */
function alert(msg){
    WScript.Echo(msg+"");
}

// Binding event handler prefix: ONIE_
var IE = WScript.CreateObject("InternetExplorer.Application","ONIE_");
IE.left=50;
IE.top = 100;
IE.height = 200;
IE.width = 350;
IE.menubar = false;
IE.toolbar = false;
IE.statusbar = false;
IE.resizable = false;
IE.navigate("c:\\temp\\readme.html");
IE.visible = true;

while(!IE.Document.Script.GetValue){ // break when page load and run
    WScript.Sleep( 300 );
}

alert("Please click OK");

//alert(IE.Document.Script);
//alert(IE.Document.body);
//alert(IE.Document.Script.GetValue);
alert("GetValue()="+IE.Document.Script.GetValue());

WScript.DisconnectObject( IE );
IE.Quit()

alert("Disconnected");

function ONIE_WindowStateChanged(state){
    alert("Event: Window State Changed to "+state);
}

// Raised from loading a document in Internet Explorer
function ONIE_DownloadBegin(){
    alert("Event: Download begins");
}

/* Raised from quitting Internet Explorer, but we're
 * disconnecting from the object before calling
 * the Quit method to terminate Internet Explorer, so 
 * the dialog box isn't shown. */
function ONIE_OnQuit(){
    alert("Event: Quit Internet Explorer");
}




readme.html:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title> Test </title>
 </head>


 <body>
  <label>请输入:<input id="box" style="width:120px;" /></label>
  <script type="text/javascript">
    function GetValue(){
      return document.getElementById("box").value;
    }
  </script>
 </body>
</html>



关于Windows Scripting Host这个很实用的古董编程技术,Jimbowhy 收集了大量收藏级的资料,请到云盤免费下载:

http://pan.baidu.com/s/1i3Br5OD

包括:

Advanced VBSript for Microsoft Windows Administrators.pdf
Advanced Windows Script Host Developers Guide (2003) .pdf
IVIEWERS.DLL
Microsoft VBScript Step by Step.pdf
Microsoft Windows脚本技术.CHM
OLEVIEW.EXE
scd56chs.exe JScript & VBScript 官方参考手册 5.6中文版
script56.chm JScript & VBScript 官方参考手册 5.6 e文版
scripten.5.7.0.16535.win2k.exe  JScript & VBScript 安装程序
scripten.5.7.0.16535.win2k3 .exe
scripthost20dev.chm  Microsoft Windows Script Host 2.0 Developer’s Guide / Günter Born.<
script_repository10.chm System Administration Scripting Guide Script RepositoryVersion 1.0, May 2002
VBScript Programmer‘s Reference, 3rd Edition.pdf
VBScript程序员参考手册.pdf
VBS_常用脚本.docx

sct10en.exe    Microsoft Script Control 1.0


InternetExplorer对象参考:http://msdn.microsoft.com/en-us/library/aa752084

 

VBA的inputBox函数的JScript模拟