使用默认操作系统程序打开所有文件类型



有没有办法链接以使用默认操作系统程序而不是Electron内部打开所有文件扩展名?

我的文件名是从 JSON 文件加载的。(Value.url 是在搜索过程中动态拉入的文件名(

我修改了下面的代码以将单击事件链接到 openBtnId,但现在我收到"电子未定义"。 我有常量外壳 = require('electron'(.shell;在我的主JS中。

function renderHTML(data) {
var htmlString = "";
$('#aceCategory').empty();
for (i = 0; i < data.length; i++) {
htmlString += "<p class='categoryName'>" + data[i].category + "</p>" + "<tr>" + "<td class='feedDesc'>" + "<b>" + data[i].name +
"</b>" + "<br>" + data[i].desc + "</br>" + "<br>" + "<input type='button' id='openBtn' style='border-radius: 25px; outline: none' value='Open Link'  >" + "</td>" +
"</tr>";
}
aceFeedTable.insertAdjacentHTML('beforeend', htmlString)
$(document).on("click", "#openBtn", function() {
electron.shell.openItem(data[i].url);
});
}

你可以使用 shell.openItem(fullPath( 来实现这一点。

const {shell} = require("electron");
shell.openItem("/path/to/my/file");

这必须在主进程中或在nodeIntegration设置为true的浏览器窗口中完成。

我将nodeIntegration设置为true并添加了window.$ = window.jQuery = require('jquery'(; 到我的主窗口 html。现在它可以识别shell.openItem。

最新更新