我在网上找到了这个关于如何运行 WebView
的非常酷的示例与德诺。
是否可以从放置在 html 模板中的 HTML 按钮元素调用 Deno 应用程序中的函数?
看一看:
// Importing the webview library
import { WebView } from "https://deno.land/x/webview/mod.ts";
// Creating an HTML page
let html = `
<html>
<body>
<h1>Hello from deno v${Deno.version.deno}</h1>
<button type="button" onclick="test()">RUN TEST FUNCTION</button>
</body>
</html>
`;
function test() {
console.log('You really can do that!');
}
// Creating and configuring the webview
const webview = new WebView({
title: "Deno Webview Example",
url: "data:text/html," + html,
// url: 'https://www.google.com',
width: 768,
height: 1024,
resizable: true,
debug: true,
frameless: false
});
// Running the webview
webview.run();
要运行此代码,您需要:deno run -A --unstable webview.ts
最佳答案
使用 WebView.bind()
.
使这个问题中的示例工作可能很简单(test()
将成为一个全局函数,正如点击处理程序所期望的那样):
@@ -27,5 +27,8 @@ const webview = new WebView({
debug: true,
frameless: false
});
+
+webview.bind('test', test);
+
// Running the webview
webview.run();
关于javascript - 从 WebView 调用 Deno 函数。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63657464/