我已经创建了一个HTA,它将充当应用程序安装程序。我需要能够传递变量从一个函数到另一个,在HTA内。下面是代码:
<!doctype html>
<html>
<script language="vbscript">
set wsh=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
function htaresize
height=480
width=640
window.resizeto width,height
screenheight=document.parentwindow.screen.availheight
screenwidth=document.parentwindow.screen.availwidth
postop=(screenheight-height)/2
posleft=(screenwidth-width)/2
window.moveto posleft,postop
end function
htaresize()
function window_onload
sfl="_a.txt"
set fil=fso.opentextfile(sfl,1)
do until fil.atendofstream
sln=fil.readline
set opt=document.createelement("option")
opt.text=sln
opt.value=sln
availapps.add(opt)
loop
fil.close
end function
function findsel
sel=""
for each i in availapps.options
if i.selected then
sel=sel & i.value
sel=i.value
end if
next
if len(sel)>0 then
select case sel
case "7-Zip"
case "Adobe AIR"
case "Adobe Flash Player"
case "Adobe Acrobat Reader DC"
case "Adobe Shockwave Player"
case "Cisco WebEx"
case "Citrix Receiver"
case "FileZilla"
case "Gimp"
case "Google Chrome"
case "InfraRecorder"
case "FolderSizes"
case "Microsoft Office"
case "Java"
case "Rufus"
end select
if len(sel)>0 then
jpg="<img src='./_dependencies/" & sel & ".jpg'>"
txt="<p>You have chosen to install " & sel & " on this computer.</p>"
war="<p>Please note - If User Account Control (UAC) is active on this system, some functions of this application may be restricted and/or non-functional. If installation fails or the application doesn't function as expected, try temporarily disabling your antivirus or security software and install again as antivirus or other security software could cause the installation to fail.</p><p>Continuing the installation of this software may impair or destabilize the correct operation of this system either immediately or in the future.</p>"
btn="<br><br><input class='button' name='button_cont' onclick='install' type='button' value='INSTALL'>"
end if
dataarea.innerhtml=jpg & txt & war & btn
end if
end function
function install
msgbox sel & " is now being installed. Please wait..."
'* * * perform actual install procedure here * * *
end function
</script>
<hta:application
applicationname="hta"
border="none"
borderstyle="normal"
caption="yes"
contextmenu="no"
commandline=""
icon=""
id="hta"
innerborder="no"
maximizebutton="no"
minimizebutton="no"
navigable="yes"
scroll="no"
scrollflat="yes"
selection="no"
showintaskbar="no"
singleinstance="yes"
systemmenu="no"
version="2016.11.07"
windowstate="normal" />
<head>
<style media="screen" type="text/css">
* {
font:12px "Arial", "Calibri", "Franklin Gothic Book", "Gill Sans MT", "Lucida Sans", "Microsoft Sans Serif", "MS Outlook", "Tahoma", "Verdana" sans-serif;
}
html {
background:#fff;
color:#000;
height:100%;
margin:0;
padding:0;
width:100%;
}
body {
border:1px solid #000;
height:478px;
margin:0;
padding:0;
width:638px;
}
a {
text-decoration:none;
}
div#wrap {
height:100%;
margin:0;
padding:0;
width:100%;
}
div#top {
background-color:#0066cb;
border-bottom:1px solid #000;
color:#000;
height:40px;
margin:0;
overflow:hidden;
padding:5px;
text-align:center;
width:628px;
}
div#top h1 {
font-size:36px;
font-weight:900;
text-align:center;
}
div#left {
background-color:#99cdff;
border-right:1px solid #000;
color:#000;
float:left;
height:385px;
margin:0;
overflow:hidden;
padding:5px;
text-align:center;
width:187px;
}
div#right {
float:right;
height:365px;
margin:0;
overflow:hidden;
padding:10px;
text-align:center;
vertical-align:middle;
width:420px;
}
div#bottom {
background-color:#0066cb;
border-top:1px solid #000;
height:21px;
margin:0;
overflow:hidden;
padding:5px;
text-align:right;
width:628px;
}
span#dataarea {
text-align:center;
padding-top:187px;
}
.right-align {
text-align:right;
}
.coltitle {
font-size:14px;
font-weight:900;
}
.indent {
padding-left:30px;
}
.button {
margin:0;
padding:0;
width:75px;
}
</style>
<title>Application Installer</title>
</head>
<body>
<div id="wrap">
<div id="top">
<h1 class="right-align">APPLICATION INSTALLER</h1>
</div>
<div id="left">
<br />
<p class="coltitle">Available Applications</p>
<select id="listbox" size="18" name="availapps"></select>
<br /><br />
<input class="button" name="select" type="button" onclick="findsel" value="SELECT">
</div>
<div id="right">
<span id="dataarea"></span>
</div>
<div id="bottom">
<input class="button" name="button_exit" onclick="window.close" type="button" value="EXIT">
</div>
</div>
</body>
</html>
因此,目标是能够从"install"函数中读取在"findsel"函数中建立的"sel"变量。
这可能吗?
提前感谢!
明白了。在脚本部分的开头,在任何函数之前,我添加了…
dim choice
然后,在"findsel"函数中,我添加了…
choice=sel
最后,在"install"函数中,我修改了…
msgbox sel & " is now being installed. Please wait..."
……
msgbox choice & " is now being installed. Please wait..."
谢谢。