首页 > 解决方案 > 使用按钮打开桌面程序?

问题描述

我正在尝试创建一个简单的网页,单击按钮后,它将打开我桌面上的 Excel 工作表...我的文件路径是否错误?或者是错误的函数调用?

我已经尝试过一个简单的 .open 和现在的 .location ...

<!DOCTYPE html>
<html>
<body>

<p>This button will open Excel Sheet:</p>
<button type="button" onclick="myFunction()">This goes to the Excel Doc</button>
<script>
function myFunction() {
    window.location("C:\Users\jamiller\Desktop\spreadsheet.xlsx");
}
</script>
</body>
</html>

该按钮不做任何事情,它应该打开excel文件

标签: javascripthtmlexcel

解决方案


window.location是对象,它不会做你想做的事。有关window.location的更多信息,你可以在这里找到

如果您想使用 Desktop Program 打开文档,您应该使用协议处理程序。对于 Windows 操作系统,您可以找到关联的位置:控制面板 > 程序 > 默认程序 > 设置关联、协议

如何使用它:

Example: ms-excel:ofv|u|https://contoso/Q4/budget.xls

但!

Command argument: a URI to the document, based on the http or https scheme

更多示例...

您可以使用 href 属性添加指向页面的链接:

<a href="steam://rungameid/730">Run CS:GO</a>

此示例将启动 Steam 并运行 CS:GO

或者,您可以使用此 URI 方案启动 Microsoft Store

ms-windows-store://navigatetopage/?Id=Games

推荐阅读