我需要为自动运行CD创建一个启动器,它会创建使用VBScript从CD上打开文件(pdf,视频等)的按钮。
我在.HTA中有以下代码
shell = new ActiveXObject("WScript.Shell").Run('My eBooks\Triniscene Link Me Campaign.pdf',1,false);
,按钮是
<a href="javascript:void(0)" id="link_id">pdf 1</a>
然而,点击链接打开Internet Explorer而不是文件(它没有显示pdf的事件)
我希望能够使用系统的默认应用程序触发文件的打开
答案 0 :(得分:2)
使用Vbscript尝试此HTA:
<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Run Some Files"
BORDER="THIN"
BORDERSTYLE="NORMAL"
ICON="Explorer.exe"
INNERBORDER="NO"
MAXIMIZEBUTTON="NO"
MINIMIZEBUTTON="NO"
SCROLL="NO"
SELECTION="NO"
SINGLEINSTANCE="YES"/>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<title>Run Some Files</title>
<SCRIPT LANGUAGE="VBScript">
'************************************************************************************
Option Explicit
Sub window_onload()
CenterWindow 400,360
End Sub
'************************************************************************************
Sub CenterWindow(x,y)
Dim iLeft,itop
window.resizeTo x,y
iLeft = window.screen.availWidth/2 - x/2
itop = window.screen.availHeight/2 - y/2
window.moveTo ileft,itop
End Sub
'************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'************************************************************************************
Sub Run(MyFile)
Dim ws,return
Set ws = CreateObject("wscript.Shell")
On Error Resume Next
return = ws.run(DblQuote(MyFile),False)
If Err <> 0 Then
MsgBox "An unknown error occurred",VbCritical,"An unknown error occurred"
End If
End Sub
'************************************************************************************
</script>
</head>
<BODY text=white bgcolor="DarkOrange" TOPMARGIN="1" LEFTMARGIN="1">
<p>In Links List :</p>
<ol>
<li><a href="#" onClick="Call Run('My eBooks\Triniscene Link Me Campaign.pdf')"> Triniscene Link Me Campaign 1</a></li>
<br><br>
<li><a href="#" onClick="Call Run('My eBooks\MyPDF File 2.pdf')"> Triniscene Link Me Campaign 2</a></li>
</ol>
<p>In Buttons List :</p>
<center><button onclick="Call Run('My eBooks\Triniscene Link Me Campaign.pdf')"> Triniscene Link Me Campaign 1</button>
<br><br>
<center><button onclick="Call Run('My eBooks\MyPDF File 2.pdf')"> Triniscene Link Me Campaign 2</button>
</body>
</html>