javascript - 使用按钮打开桌面程序?
问题描述
我正在尝试创建一个简单的网页,单击按钮后,它将打开我桌面上的 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文件
解决方案
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
推荐阅读
- python - FileNotFoundError: [Errno 2] No such file or directory instabot 错误
- python - 如何使用熊猫从现有列中的值创建新的二分列
- gcc - 为没有 root 权限的 nvcc 指定 GCC 版本
- flutter - 从 Firebase 中删除快照
- python - 了解并发 Locust 用户
- javascript - 如何在 reactJS 中创建 onclick 函数?
- crowdsourcing - Toloka 质量控制中的“最近使用的值”
- python - 如果来自另一个对象的字符串包含子字符串,则从列表中删除项目
- node.js - NodeJs 监视文件 Chokidar 并使用 FFMPEG 创建缩略图,代码挂起。内存堵塞?
- android - 如何测试 Recycler 视图列表中的文本视图值?(用浓缩咖啡)