-1

I'm trying to build a local HTA (HTML Application) that will send me to a website I designate. I've got most of it working, as in it currently allows me to type in an address and choose whether to open that URL in either Internet Explorer or Firefox (both in normal and in private).

What I'm asking is if there is a vbscript I can add onto my HTA that will allow me to drag and drop a shortcut that is on my desktop and click a button to do the same as typing it out. Essentially, I would love for it to be similar to Google Image search. Like you can either type in or drag and drop an image to search. This is just for me to quickly open webpages that I have a shortcut saved. I know i could use the favorites option, but I often use many different computers and I have a flash drive that has all my stuff on it.

4

2 回答 2

1

您想拖动文件(在这种情况下为 url 快捷方式)并将其放在打开的 .hta 窗口中吗?如果是这样,那么看起来您正在寻找的内容尚未在 HTML 应用程序中实现。

编辑

如果您有最新的 Internet Explorer 版本 (9+),那么您可以使用 HTML5 原生 拖放功能。由于我使用的是 IE8 是最高版本的 XP,因此我无法应对这一挑战。

如果这很困难或不适用,那么可以考虑计划 B,在哪里可以在启动时创建一个功能来扫描您Desktop*.URL文件并将它们填充到Select元素中,因此您将以如下方式结束:

<select id="urlList">
  <option value="" selected>---</option>
  <option value="http://...">Shortcut1.url</option>
  <option value="http://...">Shortcut2.url</option>
</select>
<input id="urlAddress" type="text">

...并且可以OnChange通过在您的部分中包含一个处理程序来使用事件来控制它Head

Sub urlList_OnChange()
    Document.All.urlAddress.Value = _
        Me.Options(Me.selectedIndex).Value
End Sub

这是一个快速入门的片段。

Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strDesktop)

For Each f In fld.Files
    If f.Type = "Internet Shortcut" Then
        MsgBox f.Path & vbNewLine & ReadURL(f.Path)
    End If
Next

Function ReadURL(urlFile)
    With CreateObject("Scripting.FileSystemObject")
        With .OpenTextFile(urlFile, 1)
            .SkipLine
            ReadURL = (Split(.ReadLine, "="))(1)
        End With
    End With
End Function
于 2013-04-08T17:04:46.587 回答
0

是的,您可以,请参阅 Hey, Scripting Guy 的这篇文章(Vbscript 和 Powershell 的最佳资源)。将某些东西拖到快捷方式上几乎与将参数传递给脚本(此处为 HTA)相同。

http://blogs.technet.com/b/heyscriptingguy/archive/2005/04/20/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts.aspx

于 2013-04-08T15:33:00.553 回答