[英]Calling Deno function from WebView. How?
我在網上找到了這個非常酷的示例,說明如何使用 Deno 運行WebView
。
是否可以從放置在 html 模板內的 HTML 按鈕元素調用您的 Deno 應用程序內的 function?
看一看:
// 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()
將成為一個全局 function,正如點擊處理程序所期望的那樣):
@@ -27,5 +27,8 @@ const webview = new WebView({
debug: true,
frameless: false
});
+
+webview.bind('test', test);
+
// Running the webview
webview.run();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.