|
资讯缩略图:
资讯发布日期:2025-08-08
资讯发布简介:AIWROK软件苹果IOS控件[WebView]方法小结
资讯关键词:AIWROK软件苹果IOS控件[WebView]方法小结
资讯所属分类:IT资讯
联系:
① 本信息收集于网络,如有不对的地方欢迎联系我纠正! ② 本信息免费收录,不存在价格的问题! ③ 如果您的网站也想这样出现在这里,请您加好友情链接,我当天会审核通过!
④友情链接关键字:软件网站分类目录 网址:http://www.postbbs.com/
资讯详细描述
 | |  |  | AIWROK软件苹果IOS控件[WebView]方法小结
📌show显示界面 类别 | 详情说明 | 方法功能 | 显示界面 | 方法签名 | Void show() | 返回值 | Void | 参数 | 无 | 案例 | var web = new WebView() web.show(); web.loadHtml(` <!DOCTYPE html> <html lang="en"> < head > < meta charset = "UTF-8" > < title > WKWebView JS to Swift </ title > < style > body { font - family: -apple - system, BlinkMacSystemFont, sans - serif; padding: 40px; background - color: #f2f2f7; text - align: center; } button { font-size: 18px; padding: 12px 24px; margin: 10px; border: none; border-radius: 8px; background-color: #007aff; color: white; cursor: pointer; } button: hover { background - color: #005fd1; } </ style > </ head > < body > < h1 > Swift 调用演示 </ h1 > < button > 设置值 </ button > < button > 加载脚本 </ button > < script > async function main() { //写入配置参数 setConfig('a', '6666') //获取配置参数 const result = await getConfig("a"); //吐司提示 toast(result.toString()) //运行脚本代码,脚本要写到lamada表达式里 runJS(() => { //脚本写这里 printl("1233") }) //运行脚本文件 runFile("主脚本.js") } </ script > </ body > </ html > `) |
📌loadFile 加载本地文件 类别 | 详情说明 | 方法功能 | 加载本地文件 | 方法签名 | Void loadFile(String path) | 返回值 | Void | 参数 | - String path :文件路径 | 案例 | var fileLoader = new FileLoader(); fileLoader.loadFile("/sdcard/test.txt"); // 加载指定路径的本地文件 |
📌loadHtml 加载 HTML内容 类别 | 详情说明 | 方法功能 | 加载 HTML 内容 | 方法签名 | Void loadHtml(String html) | 返回值 | Void | 参数 | - String html :HTML 字符串 | 案例 | var webView = new WebView(); webView.loadHtml("<h1>Hello</h1>"); // 加载 HTML 内容 |
📌dismiss关闭界面 类别 | 详情说明 | 方法功能 | 关闭界面 | 方法签名 | Void dismiss() | 返回值 | Void | 参数 | 无 | 案例 | var window = new Window(); window.dismiss(); // 关闭该界面 |
📌loadUrl加载网页URL 类别 | 详情说明 | 方法功能 | 加载网页 URL | 方法签名 | Void loadUrl(String url) | 返回值 | Void | 参数 | - String url :网址字符串 | 案例 | var webView = new WebView(); webView.loadUrl("https://www.example.com"); // 加载指定网址的网页 |
完整演示例子:
- //🍎交流QQ群711841924
- // 创建一个完整的 WebView 示例
- function createWebViewExample() {
- // 创建 WebView 实例
- var web = new WebView();
-
- // 显示界面
- web.show();
-
- // 加载 HTML 冣容
- web.loadHtml(`
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>WebView 控件示例</title>
- <style>
- body {
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
- padding: 20px;
- background-color: #f5f5f5;
- text-align: center;
- }
- .container {
- max-width: 600px;
- margin: 0 auto;
- background: white;
- border-radius: 10px;
- padding: 30px;
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
- }
- h1 {
- color: #333;
- margin-bottom: 30px;
- }
- button {
- font-size: 16px;
- padding: 12px 24px;
- margin: 10px;
- border: none;
- border-radius: 6px;
- background-color: #007aff;
- color: white;
- cursor: pointer;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #005fd1;
- }
- button.secondary {
- background-color: #34c759;
- }
- button.secondary:hover {
- background-color: #2da44b;
- }
- button.warning {
- background-color: #ff9500;
- }
- button.warning:hover {
- background-color: #e08400;
- }
- .result {
- margin: 20px 0;
- padding: 15px;
- background-color: #f0f0f0;
- border-radius: 5px;
- min-height: 20px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>WebView 控件功能演示</h1>
-
- <div>
- <button onclick="testSetConfig()">设置配置</button>
- <button onclick="testGetConfig()">获取配置</button>
- </div>
-
- <div>
- <button class="secondary" onclick="testToast()">显示提示</button>
- <button class="secondary" onclick="testRunJS()">运行JS代码</button>
- </div>
-
- <div>
- <button class="warning" onclick="loadExternalUrl()">加载外部网页</button>
- <button class="warning" onclick="loadLocalFile()">加载本地文件</button>
- </div>
-
- <button style="background-color:#ff3b30" onclick="closeWebView()">关闭界面</button>
-
- <div class="result" id="result">
- 操作结果将显示在这里
- </div>
- </div>
- <script>
- // 显示操作结果
- function showResult(message) {
- document.getElementById('result').innerText = message;
- }
-
- // 设置配置示例
- function testSetConfig() {
- setConfig('username', '张三');
- setConfig('lastLogin', new Date().toString());
- showResult('配置已设置: username=张三');
- }
-
- // 获取配置示例
- async function testGetConfig() {
- try {
- const username = await getConfig('username');
- showResult('获取到配置: username=' + username);
- } catch (error) {
- showResult('获取配置失败: ' + error);
- }
- }
-
- // 显示提示示例
- function testToast() {
- toast('这是一条提示信息!');
- showResult('已显示提示信息');
- }
-
- // 运行JS代码示例
- function testRunJS() {
- runJS(() => {
- console.log('这是在原生环境中运行的JS代码');
- // 这里可以放置需要在原生环境中执行的脚本
- printl('WebView示例: JS代码已执行');
- });
- showResult('JS代码已在原生环境中运行');
- }
-
- // 加载外部网页
- function loadExternalUrl() {
- // 注意:在实际应用中,这里会跳转到指定网址
- showResult('在实际应用中将加载 https://www.baidu.com');
- }
-
- // 加载本地文件
- function loadLocalFile() {
- // 注意:在实际应用中,这里会加载指定的本地文件
- showResult('在实际应用中将加载本地文件 /sdcard/example.html');
- }
-
- // 关闭界面
- function closeWebView() {
- // 注意:在实际应用中,这会关闭WebView界面
- showResult('在实际应用中将关闭界面');
- }
- </script>
- </body>
- </html>
- `);
-
- return web;
- }
- // 演示 WebView 的各种方法
- function demonstrateWebViewMethods() {
- printl('开始演示 WebView 控件的各种方法');
-
- // 1. 创建并显示 WebView
- var webView = createWebViewExample();
- printl('1. WebView 已创建并显示');
-
- // 2. 演示 loadUrl 方法(注释形式,避免实际跳转)
- // webView.loadUrl('https://www.baidu.com');
- printl('2. loadUrl 方法可用于加载网页 URL');
-
- // 3. 演示 loadFile 方法(注释形式)
- // webView.loadFile('/sdcard/index.html');
- printl('3. loadFile 方法可用于加载本地文件');
-
- // 4. 演示 dismiss 方法(注释形式,避免实际关闭)
- // webView.dismiss();
- printl('4. dismiss 方法可用于关闭界面');
-
- printl('WebView 控件方法演示完成');
- }
- // 运行示例
- demonstrateWebViewMethods();
复制代码
| |  | |  |
|
|