更新:我将页面上显示的图像更改为编码版本,而不是引用外部图像。我能够将图像放入 Base64 转换器,然后将图像的字符串版本复制并粘贴到文件中(在下面的代码中由
~~~
表示)。这很好用。有没有类似的方法来编码图标?
问题:我创建了一个 HTML 应用程序文件 (.hta)。为了使用户体验更加个性化,我想更改任务栏的图标(也许还有在文件资源管理器或 SharePoint 上查看时的实际文件)。我想对图像进行编码而不是使用文件的原因是,当我尝试使用网络文件时,打开 .hta 文件需要“很长时间”,而且我知道这会惹恼我的最终用户。这是一个基本网站,其中包含打开我们经常使用的模板文件的链接,目的是打开最新模板的副本,以便我们确保每个人都使用最新的模板并知道我们使用的所有工具的位置。我对此进行了相当多的研究,但似乎找不到适合我的解决方案。
我尝试过的:
ICON
中声明 < HTA:APPLICATION ... />
时使用它,类似于 < img >
的编码,但它对我不起作用。当我尝试时,什么也没发生。附加评论:只要图像经过编码并且稳定,我真的可以接受任何解决方案。
工作文件的基本结构(已更新):
<!DOCTYPE html>
<html>
<HTA:APPLICATION ID = "oMyApp" APPLICATIONNAME = "MyApp" ICON = "path" BORDER = "thick" CAPTION = "yes" SHOWINTASKBAR = "yes" SINGLEINSTANCE = "yes" SYSMENU = "yes" WINDOWSTATE = "maximize" />
<head>
<title> My App </title>
<link rel = "icon" href = "path">
<link rel = "sytlesheet" type = "text/css" href = "StyleSheet.css">
</head>
<body> <div class = "content">
<div class = "Title">
<img src = "data:image/png;base64,~~~" alt = "icon" />
<strong> My App </strong>
</div>
<div class = "main">
<div class = "column">
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
<div class = "column">
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
<div class = "column">
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
<div class = "column">
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
<a href = "path to file"> File Name </a> <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
</div>
<div class = "Footer">
<em> Comment to Users </em>
</div>
</div> </body>
</html>
请帮忙
我遇到了同样的问题,最终制作了一个“编译”脚本以方便自己。我不会在这里包含它,因为它有多个不完全相关的步骤,但摘要如下:
assets.js
文件(其中图像编码为 base64)<script src="assets.js"></script>
的实例。我的“编译器”吐出的
assets.js
文件大致如下:
(请注意,我正在使用代码库其他部分中定义的一些属性,例如
Environment.hasActiveXObject
,并且还做了一些操作,以便我可以在需要时使用带有数据 url 的资产)
var Assets = (function (a, b, c) {
var Assets = {
"icon.ico": "...", // base64 (skipped for brevity)
"icon.png": "..." // base64 (skipped for brevity)
};
try {
if (Environment.hasActiveXObject) {
function cleanup () {
a = new ActiveXObject("WScript.Shell");
b = new ActiveXObject("Scripting.FileSystemObject");
a.CurrentDirectory = b.GetSpecialFolder(2);
b.DeleteFolder(c.slice(0, -1));
}
addEvent(window, "unload", cleanup);
a = new ActiveXObject("WScript.Shell");
b = new ActiveXObject("Scripting.FileSystemObject");
c = b.GetSpecialFolder(2) + "\\MyTestProject-" + b.GetTempName() + "\\";
b.CreateFolder(c);
a.CurrentDirectory = c;
for (var FileName in Assets) {
a = new ActiveXObject("Microsoft.XMLDOM").createElement("Base64Data");
a.dataType = "bin.base64";
a.text = Assets[FileName];
b = new ActiveXObject("ADODB.Stream");
b.Type = 1;
b.Open();
b.Write(a.nodeTypedValue);
b.SaveToFile(FileName, 2);
b.Close();
Assets[FileName] = c + FileName;
}
} else {
throw "Not IE/MSHTML engine";
}
} catch (e) {
for (var FileName in Assets) {
e = FileName.split(".");
e = "." + e[e.length - 1];
Assets[FileName] = "data:" + (MIME_Types[e] ? MIME_Types[e] : "application/octet-stream") + ";base64," + Assets[FileName];
}
}
return Assets;
})();
如果您有兴趣查看我的“编译”脚本,您可以在此处进行操作。另请注意,在我的项目的早期版本中,我确实使用了命令提示符技巧并使用 CSS 隐藏了乱码,但这使 MSHTA 使用怪异模式,因为乱码会弄乱文档类型,所以我想出了这个解决方案。