提交 7b3e7d0f 编写于 作者: L lixiang

modify web docs for Interfaces sequence

Signed-off-by: Nlixiang <lixiang380@huawei.com>
上级 e4a5c505
...@@ -328,6 +328,7 @@ struct WebComponent { ...@@ -328,6 +328,7 @@ struct WebComponent {
} }
``` ```
加载的html文件。
```html ```html
<!--index.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
...@@ -447,7 +448,7 @@ struct WebComponent { ...@@ -447,7 +448,7 @@ struct WebComponent {
Button('close') Button('close')
.onClick(() => { .onClick(() => {
try { try {
if (this.msgPort && this.msgPort[1]) { if (this.msgPort && this.msgPort.length == 2) {
this.msgPort[1].close(); this.msgPort[1].close();
} else { } else {
console.error("msgPort is null, Please initialize first"); console.error("msgPort is null, Please initialize first");
...@@ -667,7 +668,7 @@ struct WebComponent { ...@@ -667,7 +668,7 @@ struct WebComponent {
.onClick(() => { .onClick(() => {
try { try {
// 通过$rawfile加载本地资源文件。 // 通过$rawfile加载本地资源文件。
this.controller.loadUrl($rawfile('xxx.html')); this.controller.loadUrl($rawfile('index.html'));
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
...@@ -694,7 +695,7 @@ struct WebComponent { ...@@ -694,7 +695,7 @@ struct WebComponent {
.onClick(() => { .onClick(() => {
try { try {
// 通过resource协议加载本地资源文件。 // 通过resource协议加载本地资源文件。
this.controller.loadUrl("resource://rawfile/xxx.html"); this.controller.loadUrl("resource://rawfile/index.html");
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
...@@ -707,8 +708,9 @@ struct WebComponent { ...@@ -707,8 +708,9 @@ struct WebComponent {
3.通过沙箱路径加载本地文件,可以参考[web](../arkui-ts/ts-basic-components-web.md#web)加载沙箱路径的示例代码。 3.通过沙箱路径加载本地文件,可以参考[web](../arkui-ts/ts-basic-components-web.md#web)加载沙箱路径的示例代码。
加载的html文件。
```html ```html
<!-- xxx.html --> <!-- index.html -->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
...@@ -1339,6 +1341,23 @@ struct Index { ...@@ -1339,6 +1341,23 @@ struct Index {
} }
``` ```
加载的html文件。
```html
<!-- index.html -->
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<body>
Hello world!
</body>
<script type="text/javascript">
function htmlTest() {
str = objName.test("test function")
console.log('objName.test result:'+ str)
}
</script>
</html>
### runJavaScript ### runJavaScript
runJavaScript(script: string, callback : AsyncCallback\<string>): void runJavaScript(script: string, callback : AsyncCallback\<string>): void
...@@ -1402,6 +1421,24 @@ struct WebComponent { ...@@ -1402,6 +1421,24 @@ struct WebComponent {
} }
``` ```
加载的html文件。
```html
<!-- index.html -->
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<body>
Hello world!
</body>
<script type="text/javascript">
function test() {
console.log('Ark WebComponent')
return "This value is from index.html"
}
</script>
</html>
```
### runJavaScript ### runJavaScript
runJavaScript(script: string): Promise\<string> runJavaScript(script: string): Promise\<string>
...@@ -1466,6 +1503,23 @@ struct WebComponent { ...@@ -1466,6 +1503,23 @@ struct WebComponent {
} }
``` ```
加载的html文件。
```html
<!-- index.html -->
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<body>
Hello world!
</body>
<script type="text/javascript">
function test() {
console.log('Ark WebComponent')
return "This value is from index.html"
}
</script>
</html>
```
### runJavaScriptExt<sup>10+</sup> ### runJavaScriptExt<sup>10+</sup>
...@@ -1565,8 +1619,11 @@ struct WebComponent { ...@@ -1565,8 +1619,11 @@ struct WebComponent {
} }
} }
} }
```
//index.html 加载的html文件。
```html
<!-- index.html -->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-gb"> <html lang="en-gb">
<body> <body>
...@@ -1677,8 +1734,11 @@ struct WebComponent { ...@@ -1677,8 +1734,11 @@ struct WebComponent {
} }
} }
} }
```
//index.html 加载的html文件。
```html
<!-- index.html -->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-gb"> <html lang="en-gb">
<body> <body>
...@@ -2174,14 +2234,15 @@ struct WebComponent { ...@@ -2174,14 +2234,15 @@ struct WebComponent {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
}) })
Web({ src: $rawfile('xxx.html'), controller: this.controller }) Web({ src: $rawfile('index.html'), controller: this.controller })
} }
} }
} }
``` ```
加载的html文件。
```html ```html
<!--xxx.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -2969,14 +3030,15 @@ struct WebComponent { ...@@ -2969,14 +3030,15 @@ struct WebComponent {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: $rawfile('index.html'), controller: this.controller })
} }
} }
} }
``` ```
加载的html文件。
```html ```html
<!--xxx.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -3041,14 +3103,15 @@ struct WebComponent { ...@@ -3041,14 +3103,15 @@ struct WebComponent {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: $rawfile('index.html'), controller: this.controller })
} }
} }
} }
``` ```
加载的html文件。
```html ```html
<!--xxx.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -3113,14 +3176,15 @@ struct WebComponent { ...@@ -3113,14 +3176,15 @@ struct WebComponent {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: $rawfile('index.html'), controller: this.controller })
} }
} }
} }
``` ```
加载的html文件。
```html ```html
<!--xxx.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
......
...@@ -90,7 +90,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) ...@@ -90,7 +90,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
let url = 'file://' + globalThis.filesDir + '/xxx.html' let url = 'file://' + globalThis.filesDir + '/index.html'
@Entry @Entry
@Component @Component
...@@ -121,6 +121,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) ...@@ -121,6 +121,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
} }
``` ```
加载的html文件。
```html ```html
<!-- index.html --> <!-- index.html -->
<!DOCTYPE html> <!DOCTYPE html>
...@@ -585,15 +586,16 @@ horizontalScrollBarAccess(horizontalScrollBar: boolean) ...@@ -585,15 +586,16 @@ horizontalScrollBarAccess(horizontalScrollBar: boolean)
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: $rawfile('index.html'), controller: this.controller })
.horizontalScrollBarAccess(true) .horizontalScrollBarAccess(true)
} }
} }
} }
``` ```
加载的html文件。
```html ```html
<!--xxx.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -638,15 +640,16 @@ verticalScrollBarAccess(verticalScrollBar: boolean) ...@@ -638,15 +640,16 @@ verticalScrollBarAccess(verticalScrollBar: boolean)
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: $rawfile('index.html'), controller: this.controller })
.verticalScrollBarAccess(true) .verticalScrollBarAccess(true)
} }
} }
} }
``` ```
加载的html文件。
```html ```html
<!--xxx.html--> <!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -1418,7 +1421,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) = ...@@ -1418,7 +1421,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: $rawfile("xxx.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onAlert((event) => { .onAlert((event) => {
console.log("event.url:" + event.url) console.log("event.url:" + event.url)
console.log("event.message:" + event.message) console.log("event.message:" + event.message)
...@@ -1448,8 +1451,9 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) = ...@@ -1448,8 +1451,9 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
} }
``` ```
``` 加载的html文件。
<!--xxx.html--> ```html
<!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -1500,7 +1504,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu ...@@ -1500,7 +1504,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
build() { build() {
Column() { Column() {
Web({ src: $rawfile("xxx.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onBeforeUnload((event) => { .onBeforeUnload((event) => {
console.log("event.url:" + event.url) console.log("event.url:" + event.url)
console.log("event.message:" + event.message) console.log("event.message:" + event.message)
...@@ -1530,8 +1534,9 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu ...@@ -1530,8 +1534,9 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
} }
``` ```
``` 加载的html文件。
<!--xxx.html--> ```html
<!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -1582,7 +1587,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) ...@@ -1582,7 +1587,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
build() { build() {
Column() { Column() {
Web({ src: $rawfile("xxx.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onConfirm((event) => { .onConfirm((event) => {
console.log("event.url:" + event.url) console.log("event.url:" + event.url)
console.log("event.message:" + event.message) console.log("event.message:" + event.message)
...@@ -1612,8 +1617,9 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) ...@@ -1612,8 +1617,9 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
} }
``` ```
``` 加载的html文件。
<!--xxx.html--> ```html
<!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -1671,7 +1677,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul ...@@ -1671,7 +1677,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
build() { build() {
Column() { Column() {
Web({ src: $rawfile("xxx.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onPrompt((event) => { .onPrompt((event) => {
console.log("url:" + event.url) console.log("url:" + event.url)
console.log("message:" + event.message) console.log("message:" + event.message)
...@@ -1702,8 +1708,9 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul ...@@ -1702,8 +1708,9 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
} }
``` ```
``` 加载的html文件。
<!--xxx.html--> ```html
<!--index.html-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -4933,6 +4940,7 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr ...@@ -4933,6 +4940,7 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr
} }
``` ```
加载的html文件。
```html ```html
<!-- index.html --> <!-- index.html -->
<!DOCTYPE html> <!DOCTYPE html>
...@@ -4993,7 +5001,7 @@ runJavaScript(options: { script: string, callback?: (result: string) => void }) ...@@ -4993,7 +5001,7 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
} }
} }
``` ```
加载的html文件。
```html ```html
<!-- index.html --> <!-- index.html -->
<!DOCTYPE html> <!DOCTYPE html>
...@@ -5009,7 +5017,6 @@ runJavaScript(options: { script: string, callback?: (result: string) => void }) ...@@ -5009,7 +5017,6 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
} }
</script> </script>
</html> </html>
``` ```
### stop<sup>(deprecated)</sup> ### stop<sup>(deprecated)</sup>
...@@ -5075,18 +5082,11 @@ clearHistory(): void ...@@ -5075,18 +5082,11 @@ clearHistory(): void
通过WebCookie可以控制Web组件中的cookie的各种行为,其中每个应用中的所有web组件共享一个WebCookie。通过controller方法中的getCookieManager方法可以获取WebCookie对象,进行后续的cookie管理操作。 通过WebCookie可以控制Web组件中的cookie的各种行为,其中每个应用中的所有web组件共享一个WebCookie。通过controller方法中的getCookieManager方法可以获取WebCookie对象,进行后续的cookie管理操作。
### setCookie<sup>(deprecated)</sup> ### setCookie<sup>(deprecated)</sup>
setCookie(url: string, value: string): boolean setCookie(): boolean
设置cookie,该方法为同步方法。设置成功返回true,否则返回false。 设置cookie,该方法为同步方法。设置成功返回true,否则返回false。
从API version 9开始不再维护,建议使用[setCookie<sup>9+</sup>](../apis/js-apis-webview.md#setcookie)代替。 从API version 9开始不再维护,建议使用[setCookie<sup>9+</sup>](../apis/js-apis-webview.md#setcookie)代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ----- | ------ | ---- | ---- | ----------------- |
| url | string | 是 | - | 要设置的cookie所属的url,建议使用完整的url。 |
| value | string | 是 | - | cookie的值。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -5106,7 +5106,7 @@ setCookie(url: string, value: string): boolean ...@@ -5106,7 +5106,7 @@ setCookie(url: string, value: string): boolean
Column() { Column() {
Button('setCookie') Button('setCookie')
.onClick(() => { .onClick(() => {
let result = this.controller.getCookieManager().setCookie("https://www.example.com", "a=b") let result = this.controller.getCookieManager().setCookie()
console.log("result: " + result) console.log("result: " + result)
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册