1
我創建了一個HTA作爲應用程序安裝程序。我需要能夠在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>
因此,我們的目標是能夠閱讀「SEL」變量「findsel」功能中建立,從「安裝」功能中。
這可能嗎?
Thanx提前!