Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Last active June 16, 2026 02:00
Show Gist options
  • Select an option

  • Save lxfly2000/24e2597008928a13e2e969a148a3a754 to your computer and use it in GitHub Desktop.

Select an option

Save lxfly2000/24e2597008928a13e2e969a148a3a754 to your computer and use it in GitHub Desktop.
用于Internet Explorer的JS测试界面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!--border设为thin后就不能改变窗口大小了-->
<!--注意title, meta, hta标签顺序不能错-->
<title>脚本交互式界面</title>
<!--IE11(ie=edge)默认禁用VBS,IE9以上可以使用Canvas, SVG标签-->
<!--IE10以上似乎不识别HTA标签-->
<!--IE8以下没有addEventListener方法,也不支持vh,因此ie=9是唯一可用项-->
<meta http-equiv="x-ua-compatible" content="ie=9">
<!--HTA默认使用区域性编码-->
<meta charset="gb2312">
<!--hta标签: https://learn.microsoft.com/en-us/previous-versions/ms536495(v=vs.85) -->
<HTA:Application id="hta"
Applicationname="Scripting Interactive Interface"
border="thick"
borderstyle="normal"
caption="yes"
icon="favicon.ico"
innerborder="no"
maximizebutton="yes"
minimizebutton="yes"
showintaskbar="true"
singleinstance="yes"
contextmenu="yes"
sysmenu="yes"
version="1.0"
windowstate="normal"
scroll="yes">
<style type="text/css">
textarea{
width: 100%;
height: calc(100vh - 60px);/*vh要求IE>=9*/
}
input{
width: 100%;
}
table{
width: 100%;
}
</style>
</head>
<body>
<textarea id="taLog">VBS参考:https://ss64.com/vb/&#10;输出文字:conlog(str)&#10;</textarea>
<table><tbody><tr>
<td>
<input id="inputExpr">
</td>
<td align="right" width="160">
<select id="scriptLang">
<option value="vbs">VBScript</option>
<option value="js" selected>JScript</option>
</select>
<!--ONCLICK默认采用JS,若要用VBS需加VBSCRIPT:-->
<button id="btnExec" onclick="evalExpr(inputExpr.value)">执行</button>
</td>
</tr></tbody></table>
</body>
<!--JS区分大小写,而VBS不区分,text/vbscript可以简写为text/vbs-->
<script type="text/vbscript">
'Sub无返回值,Function用函数名字作返回值
Sub SetWindowSize(w,h)
'在onload时无法使用不区分大小写的Screen对象
ResizeTo w*screen.deviceXDPI/96,h*screen.deviceYDPI/96
End Sub
Function VBSEval(expr)
On Error Resume Next
VBSEval=Eval(expr)
If Err Then
VBSEval=Execute(expr)
End If
End Function
</script>
<!--不加type属性,text/jscript和text/javascript等效-->
<script type="text/jscript">
function onevent(dom,ev,f){
if(dom.attachEvent){
dom.attachEvent("on"+ev,f);
}else{
dom.addEventListener(ev,f);
}
}
onevent(inputExpr,"keydown",function(e){
if(e.keyCode===0xD||e.keyCode===0xA)btnExec.click();
else if(e.keyCode===38)navigateInput(false);
else if(e.keyCode===40)navigateInput(true);
});
window.onload=function(){
SetWindowSize(400,300);//调用VBS函数不区分大小写
//IE=10,IE=11时无法获取命令行参数
conlog("启动命令:"+hta.commandLine);//获取Windows命令行
conlog("URL: "+location.href);//获取URL参数
conlog("UA: "+navigator.userAgent);
inputExpr.focus();
if(navigator.userAgent.indexOf("MSIE 9")===-1){
document.write("请安装IE9或更新版本。");
}
};
function conlog(str) {
taLog.value+=str+"\n";
taLog.scrollTop=taLog.scrollHeight;
}
var exprHistory={
entries:[],
currentIndex:-1,
navigateEntry:function(delta){
if(this.entries.length===0){
return "";
}
this.currentIndex=Math.min(Math.max(0,this.currentIndex+delta),this.entries.length-1);
return this.entries[this.currentIndex];
},
addEntry:function(str){
this.entries.push(str);
this.currentIndex=this.entries.length;
}
};
function navigateInput(isNext) {
if(exprHistory.entries.length===0){
return;
}
inputExpr.value=exprHistory.navigateEntry(isNext?1:-1);
inputExpr.focus();
}
function evalExpr(expr) {
if(expr.length===0){
inputExpr.focus();
return;
}
if(scriptLang.value==="vbs"){
conlog(VBSEval(expr));
}else{
try{
conlog(eval(expr));
}catch(e){
conlog(e);
}
}
exprHistory.addEntry(expr);
inputExpr.value="";
inputExpr.focus();
}
function readAllFile(path){
var fso=new ActiveXObject("Scripting.FileSystemObject");
return fso.OpenTextFile(path).ReadAll();
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment