electron 的html中如何获取当前的路径
在 Electron 的 HTML 文件中,可以使用 window.location 对象来获取当前的路径。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Electron App</title>
</head>
<body>
<script>
// 获取当前路径
const currentPath = window.location.pathname;
console.log(currentPath);
</script>
</body>
</html>
window.location.pathname 返回当前页面的路径部分,不包括主机名和查询参数。例如,如果当前页面的 URL 是 file:///C:/path/to/index.html,那么 window.location.pathname 的值将是 /path/to/index.html。
注意:在 Electron 中,你可能需要使用 Node.js 的模块来获取更详细的路径信息,比如使用 __dirname 来获取当前文件所在的目录路径
原文地址: https://www.cveoy.top/t/topic/ixFk 著作权归作者所有。请勿转载和采集!