ts-basic-components-web.md 155.4 KB
Newer Older
E
ester.zhou 已提交
1 2
# Web

E
ester.zhou 已提交
3 4
The **<Web\>** component can be used to display web pages.

5 6 7 8
> **NOTE**
>
> - This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> - You can preview how this component looks on a real device. The preview is not yet available in the DevEco Studio Previewer.
E
ester.zhou 已提交
9

E
ester.zhou 已提交
10
## Required Permissions
E
ester.zhou 已提交
11
To use online resources, the application must have the **ohos.permission.INTERNET** permission. For details about how to apply for a permission, see [Declaring Permissions](../../security/accesstoken-guidelines.md).
E
ester.zhou 已提交
12

E
ester.zhou 已提交
13 14
## Child Components

E
ester.zhou 已提交
15
Not supported
E
ester.zhou 已提交
16 17 18

## APIs

E
ester.zhou 已提交
19
Web(options: { src: ResourceStr, controller: WebController | WebviewController})
E
ester.zhou 已提交
20 21 22 23

> **NOTE**
>
> Transition animation is not supported.
24 25

**Parameters**
E
ester.zhou 已提交
26

E
ester.zhou 已提交
27 28 29 30
| Name       | Type                                    | Mandatory  | Description   |
| ---------- | ---------------------------------------- | ---- | ------- |
| src        | [ResourceStr](ts-types.md)               | Yes   | Address of a web page resource.|
| controller | [WebController](#webcontroller) \| [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) | Yes   | Controller.   |
31 32

**Example**
E
ester.zhou 已提交
33

E
ester.zhou 已提交
34
  Example of loading online web pages:
35 36 37 38 39
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
40
    controller: WebController = new WebController()
41 42
    build() {
      Column() {
E
ester.zhou 已提交
43
        Web({ src: 'www.example.com', controller: this.controller })
44 45 46 47
      }
    }
  }
  ```
E
ester.zhou 已提交
48 49 50
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
E
ester.zhou 已提交
51

E
ester.zhou 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

  Example of loading local web pages:
E
ester.zhou 已提交
65 66 67 68 69
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
70
    controller: WebController = new WebController()
E
ester.zhou 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    build() {
      Column() {
        Web({ src: $rawfile("index.html"), controller: this.controller })
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
      <body>
          <p>Hello World</p>
      </body>
  </html>
  ```
E
ester.zhou 已提交
88 89

## Attributes
90

E
ester.zhou 已提交
91
Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#attributes), and [border](ts-universal-attributes-border.md#attributes).
92 93 94 95 96 97 98 99

### domStorageAccess

domStorageAccess(domStorageAccess: boolean)

Sets whether to enable the DOM Storage API. By default, this feature is disabled.

**Parameters**
E
ester.zhou 已提交
100

E
ester.zhou 已提交
101 102
| Name             | Type   | Mandatory  | Default Value  | Description                                |
| ---------------- | ------- | ---- | ----- | ------------------------------------ |
103 104 105
| domStorageAccess | boolean | Yes   | false | Whether to enable the DOM Storage API.|

**Example**
E
ester.zhou 已提交
106

107 108 109 110 111
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
112
    controller: WebController = new WebController()
113 114
    build() {
      Column() {
E
ester.zhou 已提交
115 116
        Web({ src: 'www.example.com', controller: this.controller })
          .domStorageAccess(true)
117 118 119 120 121 122 123 124 125
      }
    }
  }
  ```

### fileAccess

fileAccess(fileAccess: boolean)

E
ester.zhou 已提交
126
Sets whether to enable access to the file system in the application. This setting does not affect the access to the files specified through [$rawfile(filepath/filename)](../../quick-start/resource-categories-and-access.md).
127 128

**Parameters**
E
ester.zhou 已提交
129

E
ester.zhou 已提交
130 131
| Name       | Type   | Mandatory  | Default Value | Description                  |
| ---------- | ------- | ---- | ---- | ---------------------- |
E
ester.zhou 已提交
132
| fileAccess | boolean | Yes   | true | Whether to enable access to the file system in the application. By default, this feature is enabled.|
133 134

**Example**
E
ester.zhou 已提交
135

136 137 138 139 140
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
141
    controller: WebController = new WebController()
142 143
    build() {
      Column() {
E
ester.zhou 已提交
144 145
        Web({ src: 'www.example.com', controller: this.controller })
          .fileAccess(true)
146 147 148 149 150 151 152 153 154 155 156 157
      }
    }
  }
  ```

### imageAccess

imageAccess(imageAccess: boolean)

Sets whether to enable automatic image loading. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
158

159 160
| Name        | Type   | Mandatory  | Default Value | Description           |
| ----------- | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
161
| imageAccess | boolean | Yes   | true | Whether to enable automatic image loading.|
162 163 164 165 166 167 168

**Example**
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
169
    controller: WebController = new WebController()
170 171
    build() {
      Column() {
E
ester.zhou 已提交
172 173
        Web({ src: 'www.example.com', controller: this.controller })
          .imageAccess(true)
174 175 176 177 178 179 180 181
      }
    }
  }
  ```

### javaScriptProxy

javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array\<string\>,
E
ester.zhou 已提交
182
    controller: WebController | WebviewController})
183

E
ester.zhou 已提交
184
Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. The parameters cannot be updated.
185 186

**Parameters**
E
ester.zhou 已提交
187

E
ester.zhou 已提交
188 189 190 191 192 193
| Name       | Type                                    | Mandatory  | Default Value | Description                     |
| ---------- | ---------------------------------------- | ---- | ---- | ------------------------- |
| object     | object                                   | Yes   | -    | Object to be registered. Methods can be declared, but attributes cannot.   |
| name       | string                                   | Yes   | -    | Name of the object to be registered, which is the same as that invoked in the window.|
| methodList | Array\<string\>                          | Yes   | -    | Methods of the JavaScript object to be registered at the application side. |
| controller | [WebController](#webcontroller) or [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes   | -    | Controller.                     |
194 195

**Example**
E
ester.zhou 已提交
196

197 198 199 200 201
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    controller: WebController = new WebController()
    testObj = {
      test: (data1, data2, data3) => {
        console.log("data1:" + data1)
        console.log("data2:" + data2)
        console.log("data3:" + data3)
        return "AceString"
      },
      toString: () => {
        console.log('toString' + "interface instead.")
      }
    }
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          .javaScriptProxy({
            object: this.testObj,
            name: "objName",
            methodList: ["test", "toString"],
            controller: this.controller,
        })
      }
    }
  }
  ```
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'

  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
236 237
    testObj = {
      test: (data1, data2, data3) => {
E
ester.zhou 已提交
238 239 240 241
        console.log("data1:" + data1)
        console.log("data2:" + data2)
        console.log("data3:" + data3)
        return "AceString"
242 243
      },
      toString: () => {
E
ester.zhou 已提交
244
        console.log('toString' + "interface instead.")
245 246 247 248
      }
    }
    build() {
      Column() {
E
ester.zhou 已提交
249 250 251 252 253 254 255
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          .javaScriptProxy({
            object: this.testObj,
            name: "objName",
            methodList: ["test", "toString"],
            controller: this.controller,
256 257 258 259 260 261 262 263 264 265 266 267 268
        })
      }
    }
  }
  ```

### javaScriptAccess

javaScriptAccess(javaScriptAccess: boolean)

Sets whether JavaScript scripts can be executed. By default, JavaScript scripts can be executed.

**Parameters**
E
ester.zhou 已提交
269

270 271 272 273 274
| Name             | Type   | Mandatory  | Default Value | Description               |
| ---------------- | ------- | ---- | ---- | ------------------- |
| javaScriptAccess | boolean | Yes   | true | Whether JavaScript scripts can be executed.|

**Example**
E
ester.zhou 已提交
275

276 277 278 279 280
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
281
    controller: WebController = new WebController()
282 283
    build() {
      Column() {
E
ester.zhou 已提交
284 285
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
286 287 288 289 290 291 292 293 294 295 296 297
      }
    }
  }
  ```

### mixedMode

mixedMode(mixedMode: MixedMode)

Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. By default, this feature is disabled.

**Parameters**
E
ester.zhou 已提交
298

E
ester.zhou 已提交
299 300
| Name      | Type                       | Mandatory  | Default Value           | Description     |
| --------- | --------------------------- | ---- | -------------- | --------- |
E
ester.zhou 已提交
301
| mixedMode | [MixedMode](#mixedmode)| Yes   | MixedMode.None | Mixed content to load.|
302 303

**Example**
E
ester.zhou 已提交
304

305 306 307 308 309
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
310 311
    controller: WebController = new WebController()
    @State mode: MixedMode = MixedMode.All
312 313
    build() {
      Column() {
E
ester.zhou 已提交
314 315
        Web({ src: 'www.example.com', controller: this.controller })
          .mixedMode(this.mode)
316 317 318 319 320 321 322 323 324 325 326 327
      }
    }
  }
  ```

### onlineImageAccess

onlineImageAccess(onlineImageAccess: boolean)

Sets whether to enable access to online images through HTTP and HTTPS. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
328

329 330 331 332 333
| Name              | Type   | Mandatory  | Default Value | Description            |
| ----------------- | ------- | ---- | ---- | ---------------- |
| onlineImageAccess | boolean | Yes   | true | Whether to enable access to online images through HTTP and HTTPS.|

**Example**
E
ester.zhou 已提交
334

335 336 337 338 339
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
340
    controller: WebController = new WebController()
341 342
    build() {
      Column() {
E
ester.zhou 已提交
343 344
        Web({ src: 'www.example.com', controller: this.controller })
          .onlineImageAccess(true)
345 346 347 348 349 350 351 352 353 354 355 356
      }
    }
  }
  ```

### zoomAccess

zoomAccess(zoomAccess: boolean)

Sets whether to enable zoom gestures. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
357

358 359 360 361 362
| Name       | Type   | Mandatory  | Default Value | Description         |
| ---------- | ------- | ---- | ---- | ------------- |
| zoomAccess | boolean | Yes   | true | Whether to enable zoom gestures.|

**Example**
E
ester.zhou 已提交
363

364 365 366 367 368
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
369
    controller: WebController = new WebController()
370 371
    build() {
      Column() {
E
ester.zhou 已提交
372 373
        Web({ src: 'www.example.com', controller: this.controller })
          .zoomAccess(true)
374 375 376 377 378 379 380 381 382 383 384 385
      }
    }
  }
  ```

### overviewModeAccess

overviewModeAccess(overviewModeAccess: boolean)

Sets whether to load web pages by using the overview mode. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
386

387 388
| Name               | Type   | Mandatory  | Default Value | Description           |
| ------------------ | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
389
| overviewModeAccess | boolean | Yes   | true | Whether to load web pages by using the overview mode.|
390 391

**Example**
E
ester.zhou 已提交
392

393 394 395 396 397
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
398
    controller: WebController = new WebController()
399 400
    build() {
      Column() {
E
ester.zhou 已提交
401 402
        Web({ src: 'www.example.com', controller: this.controller })
          .overviewModeAccess(true)
403 404 405 406 407 408 409 410 411 412 413 414
      }
    }
  }
  ```

### databaseAccess

databaseAccess(databaseAccess: boolean)

Sets whether to enable database access. By default, this feature is disabled.

**Parameters**
E
ester.zhou 已提交
415

E
ester.zhou 已提交
416 417
| Name           | Type   | Mandatory  | Default Value  | Description             |
| -------------- | ------- | ---- | ----- | ----------------- |
E
ester.zhou 已提交
418
| databaseAccess | boolean | Yes   | false | Whether to enable database access.|
419 420

**Example**
E
ester.zhou 已提交
421

422 423 424 425 426
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
427
    controller: WebController = new WebController()
428 429
    build() {
      Column() {
E
ester.zhou 已提交
430 431
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
432 433 434 435 436 437 438 439 440 441 442 443
      }
    }
  }
  ```

### geolocationAccess

geolocationAccess(geolocationAccess: boolean)

Sets whether to enable geolocation access. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
444

E
ester.zhou 已提交
445 446 447
| Name              | Type   | Mandatory  | Default Value | Description           |
| ----------------- | ------- | ---- | ---- | --------------- |
| geolocationAccess | boolean | Yes   | true | Whether to enable geolocation access.|
448 449

**Example**
E
ester.zhou 已提交
450

451 452 453 454 455
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
456
    controller: WebController = new WebController()
457 458
    build() {
      Column() {
E
ester.zhou 已提交
459 460 461 462 463 464 465 466 467 468 469
        Web({ src: 'www.example.com', controller: this.controller })
          .geolocationAccess(true)
      }
    }
  }
  ```

### mediaPlayGestureAccess

mediaPlayGestureAccess(access: boolean)

E
ester.zhou 已提交
470
Sets whether video playback must be started by user gestures. This API is not applicable to videos that do not have an audio track or whose audio track is muted.
E
ester.zhou 已提交
471 472 473

**Parameters**

E
ester.zhou 已提交
474 475
| Name   | Type   | Mandatory  | Default Value | Description             |
| ------ | ------- | ---- | ---- | ----------------- |
E
ester.zhou 已提交
476
| access | boolean | Yes   | true | Whether video playback must be started by user gestures.|
E
ester.zhou 已提交
477 478 479 480 481 482 483 484

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
485 486
    controller: WebController = new WebController()
    @State access: boolean = true
E
ester.zhou 已提交
487 488 489 490
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .mediaPlayGestureAccess(this.access)
491 492 493 494 495
      }
    }
  }
  ```

E
ester.zhou 已提交
496 497 498 499 500 501 502 503
### multiWindowAccess<sup>9+</sup>

multiWindowAccess(multiWindow: boolean)

Sets whether to enable the multi-window permission.

**Parameters**

E
ester.zhou 已提交
504 505
| Name        | Type   | Mandatory  | Default Value  | Description        |
| ----------- | ------- | ---- | ----- | ------------ |
E
ester.zhou 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
| multiWindow | boolean | Yes   | false | Whether to enable the multi-window permission.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
        .multiWindowAccess(true)
      }
    }
  }
  ```

E
ester.zhou 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
### horizontalScrollBarAccess<sup>9+</sup>

horizontalScrollBarAccess(horizontalScrollBar: boolean)

Sets whether to display the horizontal scrollbar, including the system default scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed.

**Parameters**

| Name        | Type   | Mandatory  | Default Value  | Description        |
| ----------- | ------- | ---- | ----- | ------------ |
| horizontalScrollBar | boolean | Yes   | true | Whether to display the horizontal scrollbar.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
        .horizontalScrollBarAccess(true)
      }
    }
  }
  ```

  ```html
  <!--xxx.html-->
  <!DOCTYPE html>
  <html>
  <head>
      <title>Demo</title>
      <style>
        body {
          width:3000px;
          height:3000px;
          padding-right:170px;
          padding-left:170px;
          border:5px solid blueviolet
        }
      </style>
  </head>
  <body>
  Scroll Test
  </body>
  </html>
  ```

### verticalScrollBarAccess<sup>9+</sup>

verticalScrollBarAccess(verticalScrollBar: boolean)

Sets whether to display the vertical scrollbar, including the system default scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed.

**Parameters**

| Name        | Type   | Mandatory  | Default Value  | Description        |
| ----------- | ------- | ---- | ----- | ------------ |
| verticalScrollBarAccess | boolean | Yes   | true | Whether to display the vertical scrollbar.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
        .verticalScrollBarAccess(true)
      }
    }
  }
  ```

  ```html
  <!--xxx.html-->
  <!DOCTYPE html>
  <html>
  <head>
      <title>Demo</title>
      <style>
        body {
          width:3000px;
          height:3000px;
          padding-right:170px;
          padding-left:170px;
          border:5px solid blueviolet
        }
      </style>
  </head>
  <body>
  Scroll Test
  </body>
  </html>
  ```


628 629 630 631 632 633 634
### cacheMode

cacheMode(cacheMode: CacheMode)

Sets the cache mode.

**Parameters**
E
ester.zhou 已提交
635

E
ester.zhou 已提交
636 637
| Name      | Type                       | Mandatory  | Default Value              | Description     |
| --------- | --------------------------- | ---- | ----------------- | --------- |
638 639 640
| cacheMode | [CacheMode](#cachemode)| Yes   | CacheMode.Default | Cache mode to set.|

**Example**
E
ester.zhou 已提交
641

642 643 644 645 646
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
647 648
    controller: WebController = new WebController()
    @State mode: CacheMode = CacheMode.None
649 650
    build() {
      Column() {
E
ester.zhou 已提交
651 652
        Web({ src: 'www.example.com', controller: this.controller })
          .cacheMode(this.mode)
653 654 655 656 657
      }
    }
  }
  ```

E
ester.zhou 已提交
658
### textZoomRatio<sup>9+</sup>
659 660 661 662 663 664

textZoomRatio(textZoomRatio: number)

Sets the text zoom ratio of the page. The default value is **100**, which indicates 100%.

**Parameters**
E
ester.zhou 已提交
665

E
ester.zhou 已提交
666 667 668
| Name          | Type  | Mandatory  | Default Value | Description           |
| ------------- | ------ | ---- | ---- | --------------- |
| textZoomRatio | number | Yes   | 100  | Text zoom ratio to set.|
669 670

**Example**
E
ester.zhou 已提交
671

672 673 674 675 676
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
677 678
    controller: WebController = new WebController()
    @State atio: number = 150
679 680
    build() {
      Column() {
E
ester.zhou 已提交
681 682
        Web({ src: 'www.example.com', controller: this.controller })
          .textZoomRatio(this.atio)
683 684 685 686 687
      }
    }
  }
  ```

E
ester.zhou 已提交
688 689 690 691 692 693 694 695
### initialScale<sup>9+</sup>

initialScale(percent: number)

Sets the scale factor of the entire page. The default value is 100%.

**Parameters**

E
ester.zhou 已提交
696 697 698
| Name    | Type  | Mandatory  | Default Value | Description           |
| ------- | ------ | ---- | ---- | --------------- |
| percent | number | Yes   | 100  | Scale factor of the entire page.|
E
ester.zhou 已提交
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    @State percent: number = 100
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .initialScale(this.percent)
      }
    }
  }
  ```

718 719 720 721 722 723 724
### userAgent

userAgent(userAgent: string)

Sets the user agent.

**Parameters**
E
ester.zhou 已提交
725

726 727 728 729 730
| Name      | Type  | Mandatory  | Default Value | Description     |
| --------- | ------ | ---- | ---- | --------- |
| userAgent | string | Yes   | -    | User agent to set.|

**Example**
E
ester.zhou 已提交
731

732 733 734 735 736
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
737 738
    controller: WebController = new WebController()
    @State userAgent:string = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'
739 740
    build() {
      Column() {
E
ester.zhou 已提交
741 742
        Web({ src: 'www.example.com', controller: this.controller })
          .userAgent(this.userAgent)
743 744 745 746
      }
    }
  }
  ```
E
ester.zhou 已提交
747

E
ester.zhou 已提交
748 749 750 751 752 753 754 755
### webDebuggingAccess<sup>9+</sup>

webDebuggingAccess(webDebuggingAccess: boolean)

Sets whether to enable web debugging.

**Parameters**

E
ester.zhou 已提交
756 757 758
| Name               | Type   | Mandatory  | Default Value  | Description         |
| ------------------ | ------- | ---- | ----- | ------------- |
| webDebuggingAccess | boolean | Yes   | false | Whether to enable web debugging.|
E
ester.zhou 已提交
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    @State webDebuggingAccess: boolean = true
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webDebuggingAccess(this.webDebuggingAccess)
      }
    }
  }
  ```

E
esterzhou 已提交
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
### blockNetwork<sup>9+</sup>

blockNetwork(block: boolean)

Sets whether to block online downloads.

**Parameters**

| Name| Type| Mandatory| Default Value| Description                           |
| ------ | -------- | ---- | ------ | ----------------------------------- |
| block  | boolean  | Yes  | false  | Whether to block online downloads.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State block: boolean = true
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .blockNetwork(this.block)
      }
    }
  }
  ```

### defaultFixedFontSize<sup>9+</sup>

defaultFixedFontSize(size: number)

E
ester.zhou 已提交
813
Sets the default fixed font size for the web page.
E
esterzhou 已提交
814 815 816 817 818

**Parameters**

| Name| Type| Mandatory| Default Value| Description                    |
| ------ | -------- | ---- | ------ | ---------------------------- |
E
ester.zhou 已提交
819
| size   | number   | Yes  | 13     | Default fixed font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
E
esterzhou 已提交
820 821 822 823 824 825 826 827 828 829

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
830
    @State fontSize: number = 16
E
esterzhou 已提交
831 832 833
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
834
          .defaultFixedFontSize(this.fontSize)
E
esterzhou 已提交
835 836 837 838 839 840 841 842 843
      }
    }
  }
  ```

### defaultFontSize<sup>9+</sup>

defaultFontSize(size: number)

E
ester.zhou 已提交
844
Sets the default font size for the web page.
E
esterzhou 已提交
845 846 847 848 849

**Parameters**

| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
E
ester.zhou 已提交
850
| size   | number   | Yes  | 16     | Default font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
E
esterzhou 已提交
851 852 853 854 855 856 857 858 859 860

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
861
    @State fontSize: number = 13
E
esterzhou 已提交
862 863 864
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
865
          .defaultFontSize(this.fontSize)
E
esterzhou 已提交
866 867 868 869 870 871 872 873 874
      }
    }
  }
  ```

### minFontSize<sup>9+</sup>

minFontSize(size: number)

E
ester.zhou 已提交
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
Sets the minimum font size for the web page.

**Parameters**

| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
| size   | number   | Yes  | 8      | Minimum font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State fontSize: number = 13
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .minFontSize(this.fontSize)
      }
    }
  }
  ```

### minLogicalFontSize<sup>9+</sup>

minLogicalFontSize(size: number)

Sets the minimum logical font size for the web page.
E
esterzhou 已提交
907 908 909 910 911

**Parameters**

| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
E
ester.zhou 已提交
912
| size   | number   | Yes  | 8      | Minimum logical font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
E
esterzhou 已提交
913 914 915 916 917 918 919 920 921 922

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
923
    @State fontSize: number = 13
E
esterzhou 已提交
924 925 926
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
927
          .minLogicalFontSize(this.fontSize)
E
esterzhou 已提交
928 929 930 931 932
      }
    }
  }
  ```

E
ester.zhou 已提交
933

E
esterzhou 已提交
934 935 936 937
### webFixedFont<sup>9+</sup>

webFixedFont(family: string)

E
ester.zhou 已提交
938
Sets the fixed font family for the web page.
E
esterzhou 已提交
939 940 941 942 943

**Parameters**

| Name| Type| Mandatory| Default Value   | Description                    |
| ------ | -------- | ---- | --------- | ---------------------------- |
E
ester.zhou 已提交
944
| family | string   | Yes  | monospace | Fixed font family to set.|
E
esterzhou 已提交
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "monospace"
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webFixedFont(this.family)
      }
    }
  }
  ```

### webSansSerifFont<sup>9+</sup>

webSansSerifFont(family: string)

E
ester.zhou 已提交
969
Sets the sans serif font family for the web page.
E
esterzhou 已提交
970 971 972 973 974

**Parameters**

| Name| Type| Mandatory| Default Value    | Description                         |
| ------ | -------- | ---- | ---------- | --------------------------------- |
E
ester.zhou 已提交
975
| family | string   | Yes  | sans-serif | Sans serif font family to set.|
E
esterzhou 已提交
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "sans-serif"
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webSansSerifFont(this.family)
      }
    }
  }
  ```

### webSerifFont<sup>9+</sup>

webSerifFont(family: string)

E
ester.zhou 已提交
1000
Sets the serif font family for the web page.
E
esterzhou 已提交
1001 1002 1003 1004 1005

**Parameters**

| Name| Type| Mandatory| Default Value| Description                    |
| ------ | -------- | ---- | ------ | ---------------------------- |
E
ester.zhou 已提交
1006
| family | string   | Yes  | serif  | Serif font family to set.|
E
esterzhou 已提交
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "serif"
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webSerifFont(this.family)
      }
    }
  }
  ```

### webStandardFont<sup>9+</sup>

webStandardFont(family: string)

E
ester.zhou 已提交
1031
Sets the standard font family for the web page.
E
esterzhou 已提交
1032 1033 1034 1035 1036

**Parameters**

| Name| Type| Mandatory| Default Value    | Description                       |
| ------ | -------- | ---- | ---------- | ------------------------------- |
E
ester.zhou 已提交
1037
| family | string   | Yes  | sans serif | Standard font family to set.|
E
esterzhou 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "sans-serif"
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webStandardFont(this.family)
      }
    }
  }
  ```

### webFantasyFont<sup>9+</sup>

webFantasyFont(family: string)

E
ester.zhou 已提交
1062
Sets the fantasy font family for the web page.
E
esterzhou 已提交
1063 1064 1065 1066 1067

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | -------- | ---- | ------- | ------------------------------ |
E
ester.zhou 已提交
1068
| family | string   | Yes  | fantasy | Fantasy font family to set.|
E
esterzhou 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "fantasy"
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webFantasyFont(this.family)
      }
    }
  }
  ```

### webCursiveFont<sup>9+</sup>

webCursiveFont(family: string)

E
ester.zhou 已提交
1093
Sets the cursive font family for the web page.
E
esterzhou 已提交
1094 1095 1096 1097 1098

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | -------- | ---- | ------- | ------------------------------ |
E
ester.zhou 已提交
1099
| family | string   | Yes  | cursive | Cursive font family to set.|
E
esterzhou 已提交
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "cursive"
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .webCursiveFont(this.family)
      }
    }
  }
  ```

E
ester.zhou 已提交
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
### darkMode<sup>9+</sup>

darkMode(mode: WebDarkMode)

Sets the web dark mode. By default, web dark mode is disabled. When it is enabled, the **\<Web>** component enables the dark theme defined for web pages if the theme has been defined in **prefer-color-scheme** of a media query, and remains unchanged otherwise. To enable the forcible dark mode, use this API with [forceDarkAccess](#forcedarkaccess9).

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | ----------- | ---- | --------------- | ------------------ |
|  mode  | [WebDarkMode](#webdarkmode9) | Yes  | WebDarkMode.Off | Web dark mode to set.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State mode: WebDarkMode = WebDarkMode.On
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .darkMode(this.mode)
      }
    }
  }
  ```

### forceDarkAccess<sup>9+</sup>

forceDarkAccess(access: boolean)

Sets whether to enable forcible dark mode for the web page. By default, this feature is turned off. This API is applicable only when dark mode is enabled in [darkMode](#darkmode9).

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | ------- | ---- | ----- | ------------------ |
| access | boolean | Yes  | false | Whether to enable forcible dark mode for the web page.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State mode: WebDarkMode = WebDarkMode.On
    @State access: boolean = true
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .darkMode(this.mode)
          .forceDarkAccess(this.access)
      }
    }
  }
  ```

### pinchSmooth<sup>9+</sup>

pinchSmooth(isEnabled: boolean)

Sets whether to enable smooth pinch mode for the web page.

**Parameters**

| Name   | Type| Mandatory| Default Value| Description                  |
| --------- | -------- | ---- | ------ | -------------------------- |
| isEnabled | boolean  | Yes  | false  | Whether to enable smooth pinch mode for the web page.|

**Example**

  ```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
  controller: web_webview.WebviewController = new web_webview.WebviewController()
  build() {
    Column() {
      Web({ src: 'www.example.com', controller: this.controller })
        .pinchSmooth(true)
    }
  }
}
  ```

E
ester.zhou 已提交
1214 1215
## Events

E
ester.zhou 已提交
1216
The universal events are not supported.
E
ester.zhou 已提交
1217

1218 1219 1220 1221 1222 1223 1224
### onAlert

onAlert(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)

Triggered when **alert()** is invoked to display an alert dialog box on the web page.

**Parameters**
E
ester.zhou 已提交
1225

1226 1227 1228 1229
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
E
ester.zhou 已提交
1230
| result  | [JsResult](#jsresult) | User operation. |
1231 1232

**Return value**
E
ester.zhou 已提交
1233

1234 1235 1236 1237 1238
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
1239

1240 1241 1242 1243 1244
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1245
    controller: WebController = new WebController()
1246 1247
    build() {
      Column() {
E
ester.zhou 已提交
1248
        Web({ src: 'www.example.com', controller: this.controller })
1249 1250
          .onAlert((event) => {
            AlertDialog.show({
E
ester.zhou 已提交
1251
              title: 'onAlert',
1252
              message: 'text',
E
ester.zhou 已提交
1253 1254 1255 1256 1257 1258 1259 1260
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
1261 1262 1263 1264 1265 1266 1267 1268
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
E
ester.zhou 已提交
1269
            return true
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
          })
      }
    }
  }
  ```

### onBeforeUnload

onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)

E
ester.zhou 已提交
1280
Triggered when this page is about to exit after the user refreshes or closes the page. This callback is triggered only when the page has obtained focus.
1281 1282

**Parameters**
E
ester.zhou 已提交
1283

1284 1285 1286 1287
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
E
ester.zhou 已提交
1288
| result  | [JsResult](#jsresult) | User operation. |
1289 1290

**Return value**
E
ester.zhou 已提交
1291

1292 1293 1294 1295 1296
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
1297

1298 1299 1300 1301 1302
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1303
    controller: WebController = new WebController()
1304 1305 1306 1307 1308
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onBeforeUnload((event) => {
E
ester.zhou 已提交
1309 1310
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
E
ester.zhou 已提交
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
            AlertDialog.show({
              title: 'onBeforeUnload',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
E
ester.zhou 已提交
1330
            return true
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
          })
      }
    }
  }
  ```

### onConfirm

onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)

Triggered when **confirm()** is invoked by the web page.

**Parameters**
E
ester.zhou 已提交
1344

1345 1346 1347 1348
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
E
ester.zhou 已提交
1349
| result  | [JsResult](#jsresult) | User operation. |
1350 1351

**Return value**
E
ester.zhou 已提交
1352

1353 1354 1355 1356 1357
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
1358

1359 1360 1361 1362 1363
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1364
    controller: WebController = new WebController()
1365 1366 1367 1368 1369
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onConfirm((event) => {
E
ester.zhou 已提交
1370 1371 1372
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
            console.log("event.result:" + event.result)
1373
            AlertDialog.show({
E
ester.zhou 已提交
1374
              title: 'onConfirm',
1375
              message: 'text',
E
ester.zhou 已提交
1376 1377 1378 1379 1380 1381 1382 1383
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
1384 1385 1386 1387 1388 1389 1390 1391
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
E
ester.zhou 已提交
1392
            return true
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
          })
      }
    }
  }
  ```

### onPrompt<sup>9+</sup>

onPrompt(callback: (event?: { url: string; message: string; value: string; result: JsResult }) => boolean)

**Parameters**
E
ester.zhou 已提交
1404

1405 1406 1407 1408
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
E
ester.zhou 已提交
1409
| result  | [JsResult](#jsresult) | User operation. |
1410 1411

**Return value**
E
ester.zhou 已提交
1412

1413 1414 1415 1416 1417
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
1418

1419 1420 1421 1422 1423
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1424
    controller: WebController = new WebController()
E
ester.zhou 已提交
1425
  
1426 1427
    build() {
      Column() {
E
ester.zhou 已提交
1428 1429
        Web({ src: 'www.example.com', controller: this.controller })
          .onPrompt((event) => {
E
ester.zhou 已提交
1430 1431 1432
            console.log("url:" + event.url)
            console.log("message:" + event.message)
            console.log("value:" + event.value)
E
ester.zhou 已提交
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
            AlertDialog.show({
              title: 'onPrompt',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
E
ester.zhou 已提交
1452
            return true
E
ester.zhou 已提交
1453 1454
          })
      }
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465
    }
  }
  ```

### onConsole

onConsole(callback: (event?: { message: ConsoleMessage }) => boolean)

Triggered to notify the host application of a JavaScript console message.

**Parameters**
E
ester.zhou 已提交
1466

1467 1468 1469 1470 1471
| Name    | Type                             | Description     |
| ------- | --------------------------------- | --------- |
| message | [ConsoleMessage](#consolemessage) | Console message.|

**Return value**
E
ester.zhou 已提交
1472

1473 1474 1475 1476 1477
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the message will not be printed to the console; returns **false** otherwise.|

**Example**
E
ester.zhou 已提交
1478

1479 1480 1481 1482 1483
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1484
    controller: WebController = new WebController()
1485 1486 1487 1488 1489
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onConsole((event) => {
E
ester.zhou 已提交
1490 1491 1492 1493 1494
            console.log('getMessage:' + event.message.getMessage())
            console.log('getSourceId:' + event.message.getSourceId())
            console.log('getLineNumber:' + event.message.getLineNumber())
            console.log('getMessageLevel:' + event.message.getMessageLevel())
            return false
1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
          })
      }
    }
  }
  ```

### onDownloadStart

onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisposition: string, mimetype: string, contentLength: number }) => void)

**Parameters**
E
ester.zhou 已提交
1506

1507 1508 1509 1510 1511 1512 1513 1514
| Name               | Type         | Description                               |
| ------------------ | ------------- | ----------------------------------- |
| url                | string        | URL for the download task.                          |
| contentDisposition | string        | Content-Disposition response header returned by the server, which may be empty.|
| mimetype           | string        | MIME type of the content returned by the server.               |
| contentLength      | contentLength | Length of the content returned by the server.                        |

**Example**
E
ester.zhou 已提交
1515

1516 1517 1518 1519 1520
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1521
    controller: WebController = new WebController()
1522 1523 1524 1525 1526
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onDownloadStart((event) => {
E
ester.zhou 已提交
1527 1528 1529 1530 1531
            console.log('url:' + event.url)
            console.log('userAgent:' + event.userAgent)
            console.log('contentDisposition:' + event.contentDisposition)
            console.log('contentLength:' + event.contentLength)
            console.log('mimetype:' + event.mimetype)
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544
          })
      }
    }
  }
  ```

### onErrorReceive

onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResourceError }) => void)

Triggered when an error occurs during web page loading. For better results, simplify the implementation logic in the callback.

**Parameters**
E
ester.zhou 已提交
1545

1546 1547 1548 1549 1550 1551
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
| error   | [WebResourceError](#webresourceerror)    | Encapsulation of a web page resource loading error.|

**Example**
E
ester.zhou 已提交
1552

1553 1554 1555 1556 1557
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1558
    controller: WebController = new WebController()
1559 1560 1561 1562 1563
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onErrorReceive((event) => {
E
ester.zhou 已提交
1564 1565 1566 1567 1568 1569 1570 1571 1572
            console.log('getErrorInfo:' + event.error.getErrorInfo())
            console.log('getErrorCode:' + event.error.getErrorCode())
            console.log('url:' + event.request.getRequestUrl())
            console.log('isMainFrame:' + event.request.isMainFrame())
            console.log('isRedirect:' + event.request.isRedirect())
            console.log('isRequestGesture:' + event.request.isRequestGesture())
            console.log('getRequestHeader_headerKey:' + event.request.getRequestHeader().toString())
            let result = event.request.getRequestHeader()
            console.log('The request header result size is ' + result.length)
1573
            for (let i of result) {
E
ester.zhou 已提交
1574
              console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue)
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
            }
          })
      }
    }
  }
  ```

### onHttpErrorReceive

onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: WebResourceResponse }) => void)

Triggered when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading.

**Parameters**
E
ester.zhou 已提交
1589

1590 1591 1592
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
E
ester.zhou 已提交
1593
| response | [WebResourceResponse](#webresourceresponse)    | Encapsulation of a resource response.|
1594 1595

**Example**
E
ester.zhou 已提交
1596

1597 1598 1599 1600 1601
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1602
    controller: WebController = new WebController()
1603 1604 1605 1606 1607
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpErrorReceive((event) => {
E
ester.zhou 已提交
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618
            console.log('url:' + event.request.getRequestUrl())
            console.log('isMainFrame:' + event.request.isMainFrame())
            console.log('isRedirect:' + event.request.isRedirect())
            console.log('isRequestGesture:' + event.request.isRequestGesture())
            console.log('getResponseData:' + event.response.getResponseData())
            console.log('getResponseEncoding:' + event.response.getResponseEncoding())
            console.log('getResponseMimeType:' + event.response.getResponseMimeType())
            console.log('getResponseCode:' + event.response.getResponseCode())
            console.log('getReasonMessage:' + event.response.getReasonMessage())
            let result = event.request.getRequestHeader()
            console.log('The request header result size is ' + result.length)
1619
            for (let i of result) {
E
ester.zhou 已提交
1620
              console.log('The request header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
1621
            }
E
ester.zhou 已提交
1622 1623
            let resph = event.response.getResponseHeader()
            console.log('The response header result size is ' + resph.length)
1624
            for (let i of resph) {
E
ester.zhou 已提交
1625
              console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
            }
          })
      }
    }
  }
  ```

### onPageBegin

onPageBegin(callback: (event?: { url: string }) => void)


Triggered when the web page starts to be loaded. This API is triggered only for the main frame content, and not for the iframe or frameset content.

**Parameters**
E
ester.zhou 已提交
1641

1642 1643 1644 1645 1646
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

**Example**
E
ester.zhou 已提交
1647

1648 1649 1650 1651 1652
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1653
    controller: WebController = new WebController()
1654 1655 1656 1657 1658
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPageBegin((event) => {
E
ester.zhou 已提交
1659
            console.log('url:' + event.url)
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
          })
      }
    }
  }
  ```

### onPageEnd

onPageEnd(callback: (event?: { url: string }) => void)


Triggered when the web page loading is complete. This API is triggered only for the main frame content.

**Parameters**
E
ester.zhou 已提交
1674

1675 1676 1677 1678 1679
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

**Example**
E
ester.zhou 已提交
1680

1681 1682 1683 1684 1685
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1686
    controller: WebController = new WebController()
1687 1688 1689 1690 1691
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPageEnd((event) => {
E
ester.zhou 已提交
1692
            console.log('url:' + event.url)
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
          })
      }
    }
  }
  ```

### onProgressChange

onProgressChange(callback: (event?: { newProgress: number }) => void)

Triggered when the web page loading progress changes.

**Parameters**
E
ester.zhou 已提交
1706

1707 1708 1709 1710
| Name        | Type  | Description                 |
| ----------- | ------ | --------------------- |
| newProgress | number | New loading progress. The value is an integer ranging from 0 to 100.|

E
ester.zhou 已提交
1711 1712
**Example**

1713 1714 1715 1716 1717
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1718
    controller: WebController = new WebController()
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onProgressChange((event) => {
            console.log('newProgress:' + event.newProgress)
          })
      }
    }
  }
  ```

### onTitleReceive

onTitleReceive(callback: (event?: { title: string }) => void)

Triggered when the document title of the web page is changed.

**Parameters**
E
ester.zhou 已提交
1738

1739 1740 1741 1742
| Name  | Type  | Description         |
| ----- | ------ | ------------- |
| title | string | Document title.|

E
ester.zhou 已提交
1743 1744
**Example**

1745 1746 1747 1748 1749
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1750
    controller: WebController = new WebController()
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onTitleReceive((event) => {
            console.log('title:' + event.title)
          })
      }
    }
  }
  ```

### onRefreshAccessedHistory

onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean }) => void)

Triggered when loading of the web page is complete. This API is used by an application to update the historical link it accessed.

**Parameters**
E
ester.zhou 已提交
1770

E
ester.zhou 已提交
1771 1772 1773
| Name        | Type   | Description                                    |
| ----------- | ------- | ---------------------------------------- |
| url         | string  | URL to be accessed.                                 |
E
ester.zhou 已提交
1774 1775 1776
| isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh](#refresh) API, and **false** means the opposite.|

**Example**
1777 1778 1779 1780 1781 1782

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1783
    controller: WebController = new WebController()
1784 1785 1786 1787 1788
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onRefreshAccessedHistory((event) => {
E
ester.zhou 已提交
1789
            console.log('url:' + event.url + ' isReload:' + event.isRefreshed)
1790 1791 1792 1793 1794 1795
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1796
### onRenderExited<sup>9+</sup>
1797 1798 1799 1800 1801 1802

onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)

Triggered when the rendering process exits abnormally.

**Parameters**
E
ester.zhou 已提交
1803

1804 1805 1806 1807
| Name             | Type                                    | Description            |
| ---------------- | ---------------------------------------- | ---------------- |
| renderExitReason | [RenderExitReason](#renderexitreason)| Cause for the abnormal exit of the rendering process.|

E
ester.zhou 已提交
1808 1809
**Example**

1810 1811 1812 1813 1814
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1815
    controller: WebController = new WebController()
1816 1817 1818 1819 1820
  
    build() {
      Column() {
        Web({ src: 'chrome://crash/', controller: this.controller })
          .onRenderExited((event) => {
E
ester.zhou 已提交
1821
            console.log('reason:' + event.renderExitReason)
1822 1823 1824 1825 1826 1827 1828 1829
          })
      }
    }
  }
  ```

### onShowFileSelector<sup>9+</sup>

E
ester.zhou 已提交
1830
onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector: FileSelectorParam }) => boolean)
1831 1832 1833 1834

Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.

**Parameters**
E
ester.zhou 已提交
1835

1836 1837 1838 1839 1840
| Name         | Type                                    | Description             |
| ------------ | ---------------------------------------- | ----------------- |
| result       | [FileSelectorResult](#fileselectorresult9) | File selection result to be sent to the **\<Web>** component.|
| fileSelector | [FileSelectorParam](#fileselectorparam9) | Information about the file selector.      |

E
ester.zhou 已提交
1841 1842
**Return value**

E
ester.zhou 已提交
1843 1844
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1845
| boolean | The value **true** means that the pop-up window provided by the system is displayed. The value **false** means that the default web pop-up window is displayed.|
E
ester.zhou 已提交
1846 1847 1848 1849

**Example**

  ```ts
1850 1851 1852 1853
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1854
    controller: WebController = new WebController()
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onShowFileSelector((event) => {
            AlertDialog.show({
              title: event.fileSelector.getTitle(),
              message: 'isCapture:' + event.fileSelector.isCapture() + " mode:" + event.fileSelector.getMode() + 'acceptType:' + event.fileSelector.getAcceptType(),
              confirm: {
                value: 'upload',
                action: () => {
                  let fileList: Array<string> = [
                    '/data/storage/el2/base/test',
                  ]
                  event.result.handleFileList(fileList)
                }
              },
              cancel: () => {
                let fileList: Array<string> = []
                event.result.handleFileList(fileList)
              }
            })
E
ester.zhou 已提交
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891
            return true
          })
      }
    }
  }
  ```

### onResourceLoad<sup>9+</sup>

onResourceLoad(callback: (event: {url: string}) => void)

Invoked to notify the **\<Web>** component of the URL of the loaded resource file.

**Parameters**

E
ester.zhou 已提交
1892 1893 1894
| Name | Type  | Description          |
| ---- | ------ | -------------- |
| url  | string | URL of the loaded resource file.|
E
ester.zhou 已提交
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onResourceLoad((event) => {
            console.log('onResourceLoad: ' + event.url)
          })
      }
    }
  }
  ```

### onScaleChange<sup>9+</sup>

onScaleChange(callback: (event: {oldScale: number, newScale: number}) => void)

Invoked when the display ratio of this page changes.

**Parameters**

E
ester.zhou 已提交
1924 1925
| Name     | Type  | Description        |
| -------- | ------ | ------------ |
E
ester.zhou 已提交
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
| oldScale | number | Display ratio of the page before the change.|
| newScale | number | Display ratio of the page after the change.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onScaleChange((event) => {
            console.log('onScaleChange changed from ' + event.oldScale + ' to ' + event.newScale)
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
          })
      }
    }
  }
  ```

### onUrlLoadIntercept

onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => boolean)

Triggered when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access.

**Parameters**
E
ester.zhou 已提交
1956

1957 1958 1959 1960 1961
| Name | Type                                    | Description     |
| ---- | ---------------------------------------- | --------- |
| data | string / [WebResourceRequest](#webresourcerequest) | URL information.|

**Return value**
E
ester.zhou 已提交
1962

1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
| Type     | Description                      |
| ------- | ------------------------ |
| boolean | Returns **true** if the access is blocked; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1974
    controller: WebController = new WebController()
1975 1976 1977 1978 1979 1980
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onUrlLoadIntercept((event) => {
            console.log('onUrlLoadIntercept ' + event.data.toString())
E
ester.zhou 已提交
1981
            return true
1982 1983 1984 1985 1986 1987 1988 1989
          })
      }
    }
  }
  ```

### onInterceptRequest<sup>9+</sup>

E
ester.zhou 已提交
1990
onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebResourceResponse)
1991

E
ester.zhou 已提交
1992
Invoked when the **\<Web>** component is about to access a URL. This API is used to block the URL and return the response data.
1993 1994

**Parameters**
E
ester.zhou 已提交
1995

1996 1997 1998 1999 2000
| Name    | Type                                    | Description       |
| ------- | ---------------------------------------- | ----------- |
| request | [WebResourceRequest](#webresourcerequest) | Information about the URL request.|

**Return value**
E
ester.zhou 已提交
2001

E
ester.zhou 已提交
2002 2003
| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
E
ester.zhou 已提交
2004 2005 2006
| [WebResourceResponse](#webresourceresponse) | If response data is returned, the data is loaded based on the response data. If no response data is returned, null is returned, indicating that the data is loaded in the original mode.|

**Example**
2007 2008 2009 2010 2011 2012

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2013 2014 2015
    controller: WebController = new WebController()
    responseweb: WebResourceResponse = new WebResourceResponse()
    heads:Header[] = new Array()
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
    @State webdata: string = "<!DOCTYPE html>\n" +
    "<html>\n"+
    "<head>\n"+
    "<title>intercept test</title>\n"+
    "</head>\n"+
    "<body>\n"+
    "<h1>intercept test</h1>\n"+
    "</body>\n"+
    "</html>"
    build() {
      Column() {
E
ester.zhou 已提交
2027
        Web({ src: 'www.example.com', controller: this.controller })
2028
          .onInterceptRequest((event) => {
E
ester.zhou 已提交
2029
            console.log('url:' + event.request.getRequestUrl())
2030 2031 2032 2033 2034 2035 2036 2037
            var head1:Header = {
              headerKey:"Connection",
              headerValue:"keep-alive"
            }
            var head2:Header = {
              headerKey:"Cache-Control",
              headerValue:"no-cache"
            }
E
ester.zhou 已提交
2038 2039 2040 2041 2042 2043 2044 2045 2046
            var length = this.heads.push(head1)
            length = this.heads.push(head2)
            this.responseweb.setResponseHeader(this.heads)
            this.responseweb.setResponseData(this.webdata)
            this.responseweb.setResponseEncoding('utf-8')
            this.responseweb.setResponseMimeType('text/html')
            this.responseweb.setResponseCode(200)
            this.responseweb.setReasonMessage('OK')
            return this.responseweb
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056
          })
      }
    }
  }
  ```

### onHttpAuthRequest<sup>9+</sup>

onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, realm: string}) => boolean)

E
ester.zhou 已提交
2057
Invoked when an HTTP authentication request is received.
2058 2059

**Parameters**
E
ester.zhou 已提交
2060

2061 2062
| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
E
ester.zhou 已提交
2063
| handler | [HttpAuthHandler](#httpauthhandler9) | User operation.  |
2064 2065 2066 2067
| host    | string                               | Host to which HTTP authentication credentials apply.|
| realm   | string                               | Realm to which HTTP authentication credentials apply. |

**Return value**
E
ester.zhou 已提交
2068

2069 2070
| Type     | Description                   |
| ------- | --------------------- |
E
ester.zhou 已提交
2071
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|
2072 2073 2074 2075 2076

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2077
  import web_webview from '@ohos.web.webview'
2078 2079 2080
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2081 2082
    controller: WebController = new WebController()
    httpAuth: boolean = false
E
ester.zhou 已提交
2083
  
2084 2085
    build() {
      Column() {
E
ester.zhou 已提交
2086 2087 2088 2089 2090 2091 2092 2093
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpAuthRequest((event) => {
            AlertDialog.show({
              title: 'onHttpAuthRequest',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
E
ester.zhou 已提交
2094
                  event.handler.cancel()
2095
                }
E
ester.zhou 已提交
2096 2097 2098 2099
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
E
ester.zhou 已提交
2100
                  this.httpAuth = event.handler.isHttpAuthInfoSaved()
E
ester.zhou 已提交
2101 2102 2103 2104 2105 2106 2107
                  if (this.httpAuth == false) {
                    web_webview.WebDataBase.saveHttpAuthCredentials(
                      event.host,
                      event.realm,
                      "2222",
                      "2222"
                    )
E
ester.zhou 已提交
2108
                    event.handler.cancel()
E
ester.zhou 已提交
2109 2110 2111 2112
                  }
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2113
                event.handler.cancel()
2114
              }
E
ester.zhou 已提交
2115
            })
E
ester.zhou 已提交
2116
            return true
2117
          })
E
ester.zhou 已提交
2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129
      }
    }
  }
  ```
### onSslErrorEventReceive<sup>9+</sup>

onSslErrorEventReceive(callback: (event: { handler: SslErrorHandler, error: SslError }) => void)

Invoked when an SSL error occurs during resource loading.

**Parameters**

E
ester.zhou 已提交
2130 2131
| Name    | Type                                | Description          |
| ------- | ------------------------------------ | -------------- |
E
ester.zhou 已提交
2132
| handler | [SslErrorHandler](#sslerrorhandler9) | User operation.|
E
ester.zhou 已提交
2133
| error   | [SslError](#sslerror9)          | Error code.          |
E
ester.zhou 已提交
2134 2135 2136 2137 2138 2139 2140 2141 2142

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2143
    controller: WebController = new WebController()
E
ester.zhou 已提交
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onSslErrorEventReceive((event) => {
            AlertDialog.show({
              title: 'onSslErrorEventReceive',
              message: 'text',
              primaryButton: {
                value: 'confirm',
                action: () => {
E
ester.zhou 已提交
2155
                  event.handler.handleConfirm()
E
ester.zhou 已提交
2156 2157 2158 2159 2160
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
E
ester.zhou 已提交
2161
                  event.handler.handleCancel()
E
ester.zhou 已提交
2162 2163 2164
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2165
                event.handler.handleCancel()
E
ester.zhou 已提交
2166 2167
              }
            })
E
ester.zhou 已提交
2168
            return true
E
ester.zhou 已提交
2169 2170 2171 2172 2173 2174 2175 2176
          })
      }
    }
  }
  ```

### onClientAuthenticationRequest<sup>9+</sup>

E
ester.zhou 已提交
2177
onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array<string>, issuers : Array<string>}) => void)
E
ester.zhou 已提交
2178 2179 2180 2181 2182

Invoked when an SSL client certificate request is received.

**Parameters**

E
ester.zhou 已提交
2183 2184
| Name     | Type                                    | Description           |
| -------- | ---------------------------------------- | --------------- |
E
ester.zhou 已提交
2185
| handler  | [ClientAuthenticationHandler](#clientauthenticationhandler9) | User operation. |
E
ester.zhou 已提交
2186 2187
| host     | string                                   | Host name of the server that requests a certificate.   |
| port     | number                                   | Port number of the server that requests a certificate.   |
E
ester.zhou 已提交
2188 2189
| keyTypes | Array<string>                            | Acceptable asymmetric private key types.   |
| issuers  | Array<string>                            | Issuer of the certificate that matches the private key.|
E
ester.zhou 已提交
2190 2191 2192 2193 2194 2195 2196 2197

  **Example**
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2198
    controller: WebController = new WebController()
E
ester.zhou 已提交
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onClientAuthenticationRequest((event) => {
            AlertDialog.show({
              title: 'onClientAuthenticationRequest',
              message: 'text',
              primaryButton: {
                value: 'confirm',
                action: () => {
E
ester.zhou 已提交
2210
                  event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem")
E
ester.zhou 已提交
2211 2212 2213 2214 2215
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
E
ester.zhou 已提交
2216
                  event.handler.cancel()
E
ester.zhou 已提交
2217 2218 2219
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2220
                event.handler.ignore()
E
ester.zhou 已提交
2221 2222
              }
            })
E
ester.zhou 已提交
2223
            return true
E
ester.zhou 已提交
2224 2225
          })
      }
2226 2227 2228
    }
  }
  ```
E
ester.zhou 已提交
2229

2230 2231 2232 2233 2234 2235 2236
### onPermissionRequest<sup>9+</sup>

onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)

Invoked when a permission request is received.

**Parameters**
E
ester.zhou 已提交
2237

E
ester.zhou 已提交
2238 2239
| Name    | Type                                    | Description          |
| ------- | ---------------------------------------- | -------------- |
E
ester.zhou 已提交
2240
| request | [PermissionRequest](#permissionrequest9) | User operation.|
2241

E
ester.zhou 已提交
2242 2243 2244 2245 2246 2247 2248
**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2249
    controller: WebController = new WebController()
E
ester.zhou 已提交
2250 2251 2252 2253 2254 2255 2256 2257 2258 2259
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPermissionRequest((event) => {
            AlertDialog.show({
              title: 'title',
              message: 'text',
              primaryButton: {
                value: 'deny',
                action: () => {
E
ester.zhou 已提交
2260
                  event.request.deny()
E
ester.zhou 已提交
2261 2262 2263 2264 2265
                }
              },
              secondaryButton: {
                value: 'onConfirm',
                action: () => {
E
ester.zhou 已提交
2266
                  event.request.grant(event.request.getAccessibleResource())
E
ester.zhou 已提交
2267 2268 2269
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2270
                event.request.deny()
E
ester.zhou 已提交
2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282
              }
            })
          })
      }
    }
  }
  ```

### onContextMenuShow<sup>9+</sup>

onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebContextMenuResult }) => boolean)

E
ester.zhou 已提交
2283
Shows a context menu after the user clicks the right mouse button or long presses a specific element, such as an image or a link.
E
ester.zhou 已提交
2284 2285 2286

**Parameters**

E
ester.zhou 已提交
2287 2288 2289 2290
| Name   | Type                                    | Description       |
| ------ | ---------------------------------------- | ----------- |
| param  | [WebContextMenuParam](#webcontextmenuparam9) | Parameters related to the context menu.    |
| result | [WebContextMenuResult](#webcontextmenuresult9) | Result of the context menu.|
E
ester.zhou 已提交
2291 2292 2293

**Return value**

E
ester.zhou 已提交
2294 2295
| Type     | Description                      |
| ------- | ------------------------ |
E
ester.zhou 已提交
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326
| boolean | The value **true** means a custom menu, and **false** means the default menu.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onContextMenuShow((event) => {
            console.info("x coord = " + event.param.x())
            console.info("link url = " + event.param.getLinkUrl())
            return true
        })
      }
    }
  }
  ```

### onScroll<sup>9+</sup>

onScroll(callback: (event: {xOffset: number, yOffset: number}) => void)

Invoked when the scrollbar of the page scrolls.

**Parameters**

E
ester.zhou 已提交
2327 2328 2329 2330
| Name    | Type  | Description        |
| ------- | ------ | ------------ |
| xOffset | number | Position of the scrollbar on the x-axis.|
| yOffset | number | Position of the scrollbar on the y-axis.|
E
ester.zhou 已提交
2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
        .onScroll((event) => {
            console.info("x = " + event.xOffset)
            console.info("y = " + event.yOffset)
        })
      }
    }
  }
  ```

### onGeolocationShow

onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocation }) => void)

Registers a callback for receiving a request to obtain the geolocation information.

**Parameters**

E
ester.zhou 已提交
2360 2361
| Name        | Type                           | Description          |
| ----------- | ------------------------------- | -------------- |
E
ester.zhou 已提交
2362
| origin      | string                          | Index of the origin.    |
E
ester.zhou 已提交
2363
| geolocation | [JsGeolocation](#jsgeolocation) | User operation.|
E
ester.zhou 已提交
2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller:WebController = new WebController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller:this.controller })
        .geolocationAccess(true)
        .onGeolocationShow((event) => {
          AlertDialog.show({
            title: 'title',
            message: 'text',
            confirm: {
              value: 'onConfirm',
              action: () => {
                event.geolocation.invoke(event.origin, true, true)
              }
            },
            cancel: () => {
              event.geolocation.invoke(event.origin, false, true)
            }
          })
        })
      }
    }
  }
  ```

### onGeolocationHide

onGeolocationHide(callback: () => void)

Triggered to notify the user that the request for obtaining the geolocation information received when **[onGeolocationShow](#ongeolocationshow)** is called has been canceled.

**Parameters**

E
ester.zhou 已提交
2405 2406 2407
| Name     | Type      | Description                |
| -------- | ---------- | -------------------- |
| callback | () => void | Callback invoked when the request for obtaining geolocation information has been canceled. |
E
ester.zhou 已提交
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller:WebController = new WebController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller:this.controller })
        .geolocationAccess(true)
        .onGeolocationHide(() => {
          console.log("onGeolocationHide...")
        })
      }
    }
  }
  ```

### onFullScreenEnter<sup>9+</sup>

onFullScreenEnter(callback: (event: { handler: FullScreenExitHandler }) => void)

Registers a callback for the component's entering into full screen mode.

**Parameters**

E
ester.zhou 已提交
2437 2438 2439
| Name    | Type                                    | Description          |
| ------- | ---------------------------------------- | -------------- |
| handler | [FullScreenExitHandler](#fullscreenexithandler9) | Function handle for exiting full screen mode.|
E
ester.zhou 已提交
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller:WebController = new WebController()
    handler: FullScreenExitHandler = null
    build() {
      Column() {
        Web({ src:'www.example.com', controller:this.controller })
        .onFullScreenEnter((event) => {
          console.log("onFullScreenEnter...")
          this.handler = event.handler
        })
      }
    }
  }
  ```

### onFullScreenExit<sup>9+</sup>
E
ester.zhou 已提交
2463

E
ester.zhou 已提交
2464
onFullScreenExit(callback: () => void)
E
ester.zhou 已提交
2465

E
ester.zhou 已提交
2466
Registers a callback for the component's exiting full screen mode.
E
ester.zhou 已提交
2467

E
ester.zhou 已提交
2468
**Parameters**
E
ester.zhou 已提交
2469

E
ester.zhou 已提交
2470 2471 2472
| Name     | Type      | Description         |
| -------- | ---------- | ------------- |
| callback | () => void | Callback invoked when the component exits full screen mode.|
E
ester.zhou 已提交
2473 2474 2475 2476 2477 2478 2479 2480

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2481 2482
    controller:WebController = new WebController()
    handler: FullScreenExitHandler = null
E
ester.zhou 已提交
2483 2484
    build() {
      Column() {
E
ester.zhou 已提交
2485 2486 2487 2488 2489 2490 2491
        Web({ src:'www.example.com', controller:this.controller })
        .onFullScreenExit(() => {
          console.log("onFullScreenExit...")
          this.handler.exitFullScreen()
        })
        .onFullScreenEnter((event) => {
          this.handler = event.handler
E
ester.zhou 已提交
2492 2493 2494 2495 2496 2497
        })
      }
    }
  }
  ```

E
ester.zhou 已提交
2498
### onWindowNew<sup>9+</sup>
E
ester.zhou 已提交
2499

E
ester.zhou 已提交
2500
onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetUrl: string, handler: ControllerHandler}) => void)
E
ester.zhou 已提交
2501

E
ester.zhou 已提交
2502
Registers a callback for window creation.
E
ester.zhou 已提交
2503 2504 2505

**Parameters**

E
ester.zhou 已提交
2506 2507 2508 2509 2510 2511
| Name          | Type                                    | Description                      |
| ------------- | ---------------------------------------- | -------------------------- |
| isAlert       | boolean                                  | Whether to open the target URL in a new window. The value **true** means to open the target URL in a new window, and **false** means to open the target URL in a new tab.|
| isUserTrigger | boolean                                  | Whether the creation is triggered by the user. The value **true** means that the creation is triggered by the user, and **false** means the opposite.  |
| targetUrl     | string                                   | Target URL.                    |
| handler       | [ControllerHandler](#controllerhandler9) | **WebController** instance for setting the new window. |
E
ester.zhou 已提交
2512 2513 2514 2515 2516

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2517
  import web_webview from '@ohos.web.webview'
E
ester.zhou 已提交
2518 2519 2520
  @Entry
  @Component
  struct WebComponent {
E
esterzhou 已提交
2521
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2522 2523
    build() {
      Column() {
E
ester.zhou 已提交
2524 2525 2526 2527
        Web({ src:'www.example.com', controller: this.controller })
        .multiWindowAccess(true)
        .onWindowNew((event) => {
          console.log("onWindowNew...")
E
esterzhou 已提交
2528
          var popController: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2529
          event.handler.setWebController(popController)
E
ester.zhou 已提交
2530 2531 2532 2533 2534 2535
        })
      }
    }
  }
  ```

E
ester.zhou 已提交
2536
### onWindowExit<sup>9+</sup>
E
ester.zhou 已提交
2537

E
ester.zhou 已提交
2538
onWindowExit(callback: () => void)
E
ester.zhou 已提交
2539

E
ester.zhou 已提交
2540
Registers a callback for window closure.
E
ester.zhou 已提交
2541 2542 2543

**Parameters**

E
ester.zhou 已提交
2544 2545 2546
| Name     | Type      | Description        |
| -------- | ---------- | ------------ |
| callback | () => void | Callback invoked when the window closes.|
E
ester.zhou 已提交
2547

2548 2549 2550 2551 2552 2553 2554
**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2555
    controller:WebController = new WebController()
2556 2557
    build() {
      Column() {
E
ester.zhou 已提交
2558 2559 2560
        Web({ src:'www.example.com', controller: this.controller })
        .onWindowExit(() => {
          console.log("onWindowExit...")
2561
        })
E
ester.zhou 已提交
2562
      }
2563 2564 2565 2566
    }
  }
  ```

E
ester.zhou 已提交
2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601
### onSearchResultReceive<sup>9+</sup>

onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMatches: number, isDoneCounting: boolean}) => void): WebAttribute

Invoked to notify the caller of the search result on the web page.

**Parameters**

| Name               | Type   | Description                                    |
| ------------------ | ------- | ---------------------------------------- |
| activeMatchOrdinal | number  | Sequence number of the current match, which starts from 0.                      |
| numberOfMatches    | number  | Total number of matches.                           |
| isDoneCounting     | boolean | Whether the search operation on the current page is complete. This API may be called multiple times until **isDoneCounting** is **true**.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
     	  .onSearchResultReceive(ret => {
            console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
              "[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
          })
      }
    }
  }
  ```

E
esterzhou 已提交
2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776
### onDataResubmitted<sup>9+</sup>

onDataResubmitted(callback: (event: {handler: DataResubmissionHandler}) => void)

Invoked when the web form data is resubmitted.

**Parameters**

| Name | Type                                            | Description              |
| ------- | ---------------------------------------------------- | ---------------------- |
| handler | [DataResubmissionHandler](#dataresubmissionhandler9) | Handler for resubmitting web form data.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
         .onDataResubmitted((event) => {
          console.log('onDataResubmitted')
          event.handler.resend();
        })
      }
    }
  }
  ```

### onPageVisible<sup>9+</sup>

onPageVisible(callback: (event: {url: string}) => void)

Invoked when the old page is not displayed and the new page is about to be visible.

**Parameters**

| Name| Type| Description                                         |
| ------ | -------- | ------------------------------------------------- |
| url    | string   | URL of the new page that is able to be visible when the old page is not displayed.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
         .onPageVisible((event) => {
          console.log('onPageVisible url:' + event.url)
        })
      }
    }
  }
  ```

### onInterceptKeyEvent<sup>9+</sup>

onInterceptKeyEvent(callback: (event: KeyEvent) => boolean)

Invoked when the key event is intercepted, before being consumed by the Webview.

**Parameters**

| Name| Type                                               | Description            |
| ------ | ------------------------------------------------------- | -------------------- |
| event  | [KeyEvent](ts-universal-events-key.md#keyevent) | Key event that is triggered.|

**Return value**

| Type   | Description                                                        |
| ------- | ------------------------------------------------------------ |
| boolean | Whether to continue to transfer the key event to the Webview kernel.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
         .onInterceptKeyEvent((event) => {
          	if (event.keyCode == 2017 || event.keyCode == 2018) {
            console.info(`onInterceptKeyEvent get event.keyCode ${event.keyCode}`)
            return true;
          }
          return false;
        })
      }
    }
  }
  ```

### onTouchIconUrlReceived<sup>9+</sup>

onTouchIconUrlReceived(callback: (event: {url: string, precomposed: boolean}) => void)

Invoked when an apple-touch-icon URL is received.

**Parameters**

| Name     | Type| Description                          |
| ----------- | -------- | ---------------------------------- |
| url         | string   | Received apple-touch-icon URL.|
| precomposed | boolean  | Whether the apple-touch-icon is precomposed.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src:'www.baidu.com', controller: this.controller })
         .onTouchIconUrlReceived((event) => {
          console.log('onTouchIconUrlReceived:' + JSON.stringify(event))
        })
      }
    }
  }
  ```

### onFaviconReceived<sup>9+</sup>

onFaviconReceived(callback: (event: {favicon: image.PixelMap}) => void)

Invoked when this web page receives a new favicon.

**Parameters**

| Name | Type                                      | Description                           |
| ------- | ---------------------------------------------- | ----------------------------------- |
| favicon | [PixelMap](../apis/js-apis-image.md#pixelmap7) | **PixelMap** object of the received favicon.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  import image from "@ohos.multimedia.image"
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State icon: image.PixelMap = undefined;
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
         .onFaviconReceived((event) => {
          console.log('onFaviconReceived:' + JSON.stringify(event))
          this.icon = event.favicon;
        })
      }
    }
  }
  ```

2777 2778
## ConsoleMessage

E
esterzhou 已提交
2779
Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole).
2780 2781 2782 2783 2784 2785 2786 2787

### getLineNumber

getLineNumber(): number

Obtains the number of rows in this console message.

**Return value**
E
ester.zhou 已提交
2788

2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799
| Type    | Description                  |
| ------ | -------------------- |
| number | Number of rows in the console message.|

### getMessage

getMessage(): string

Obtains the log information of this console message.

**Return value**
E
ester.zhou 已提交
2800

2801 2802
| Type    | Description                    |
| ------ | ---------------------- |
E
ester.zhou 已提交
2803
| string | Log information of the console message.|
2804 2805 2806 2807 2808 2809 2810 2811

### getMessageLevel

getMessageLevel(): MessageLevel

Obtains the level of this console message.

**Return value**
E
ester.zhou 已提交
2812

2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823
| Type                               | Description                    |
| --------------------------------- | ---------------------- |
| [MessageLevel](#messagelevel)| Level of the console message.|

### getSourceId

getSourceId(): string

Obtains the path and name of the web page source file.

**Return value**
E
ester.zhou 已提交
2824

2825 2826 2827 2828 2829 2830
| Type    | Description           |
| ------ | ------------- |
| string | Path and name of the web page source file.|

## JsResult

E
esterzhou 已提交
2831
Implements the **JsResult** object, which indicates the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box. For the sample code, see [onAlert Event](#onalert).
2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851

### handleCancel

handleCancel(): void

Notifies the **\<Web>** component of the user's cancel operation in the dialog box.

### handleConfirm

handleConfirm(): void

Notifies the **\<Web>** component of the user's confirm operation in the dialog box.

### handlePromptConfirm<sup>9+</sup>

handlePromptConfirm(result: string): void

Notifies the **\<Web>** component of the user's confirm operation in the dialog box as well as the dialog box content.

**Parameters**
E
ester.zhou 已提交
2852

2853 2854 2855 2856
| Name   | Type  | Mandatory  | Default Value | Description       |
| ------ | ------ | ---- | ---- | ----------- |
| result | string | Yes   | -    | User input in the dialog box.|

E
ester.zhou 已提交
2857 2858
## FullScreenExitHandler<sup>9+</sup>

E
ester.zhou 已提交
2859
Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9).
E
ester.zhou 已提交
2860 2861 2862 2863 2864 2865 2866 2867 2868

### exitFullScreen<sup>9+</sup>

exitFullScreen(): void

Exits full screen mode.

## ControllerHandler<sup>9+</sup>

E
esterzhou 已提交
2869
Implements a **WebviewController** object for new **\<Web>** components. For the sample code, see [onWindowNew](#onwindownew9).
E
ester.zhou 已提交
2870 2871 2872

### setWebController<sup>9+</sup>

E
esterzhou 已提交
2873
setWebController(controller: WebviewController): void
E
ester.zhou 已提交
2874

E
esterzhou 已提交
2875
Sets a **WebviewController** object.
E
ester.zhou 已提交
2876 2877 2878

**Parameters**

E
ester.zhou 已提交
2879 2880
| Name       | Type         | Mandatory  | Default Value | Description                     |
| ---------- | ------------- | ---- | ---- | ------------------------- |
E
esterzhou 已提交
2881
| controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes   | -    | **WebviewController** object of the **\<Web>** component.|
E
ester.zhou 已提交
2882

2883 2884
## WebResourceError

E
esterzhou 已提交
2885
Implements the **WebResourceError** object. For the sample code, see [onErrorReceive](#onerrorreceive).
2886 2887 2888 2889 2890 2891 2892 2893

### getErrorCode

getErrorCode(): number

Obtains the error code for resource loading.

**Return value**
E
ester.zhou 已提交
2894

2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905
| Type    | Description         |
| ------ | ----------- |
| number | Error code for resource loading.|

### getErrorInfo

getErrorInfo(): string

Obtains error information about resource loading.

**Return value**
E
ester.zhou 已提交
2906

2907 2908 2909 2910 2911 2912
| Type    | Description          |
| ------ | ------------ |
| string | Error information about resource loading.|

## WebResourceRequest

E
esterzhou 已提交
2913
Implements the **WebResourceRequest** object. For the sample code, see [onErrorReceive](#onerrorreceive).
2914 2915 2916 2917 2918 2919 2920 2921

### getRequestHeader

getResponseHeader() : Array\<Header\>

Obtains the information about the resource request header.

**Return value**
E
ester.zhou 已提交
2922

2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933
| Type                        | Description        |
| -------------------------- | ---------- |
| Array\<[Header](#header)\> | Information about the resource request header.|

### getRequestUrl

getRequestUrl(): string

Obtains the URL of the resource request.

**Return value**
E
ester.zhou 已提交
2934

2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945
| Type    | Description           |
| ------ | ------------- |
| string | URL of the resource request.|

### isMainFrame

isMainFrame(): boolean

Checks whether the resource request is in the main frame.

**Return value**
E
ester.zhou 已提交
2946

2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957
| Type     | Description              |
| ------- | ---------------- |
| boolean | Whether the resource request is in the main frame.|

### isRedirect

isRedirect(): boolean

Checks whether the resource request is redirected by the server.

**Return value**
E
ester.zhou 已提交
2958

2959 2960
| Type     | Description              |
| ------- | ---------------- |
E
ester.zhou 已提交
2961
| boolean | Whether the resource request is redirected by the server.|
2962 2963 2964 2965 2966 2967 2968 2969

### isRequestGesture

isRequestGesture(): boolean

Checks whether the resource request is associated with a gesture (for example, a tap).

**Return value**
E
ester.zhou 已提交
2970

2971 2972
| Type     | Description                  |
| ------- | -------------------- |
E
ester.zhou 已提交
2973
| boolean | Whether the resource request is associated with a gesture (for example, a tap).|
2974 2975

## Header
E
ester.zhou 已提交
2976

E
ester.zhou 已提交
2977
Describes the request/response header returned by the **\<Web>** component.
E
ester.zhou 已提交
2978

2979 2980 2981 2982
| Name         | Type    | Description           |
| ----------- | ------ | ------------- |
| headerKey   | string | Key of the request/response header.  |
| headerValue | string | Value of the request/response header.|
E
ester.zhou 已提交
2983 2984


2985
## WebResourceResponse
E
ester.zhou 已提交
2986

E
esterzhou 已提交
2987
Implements the **WebResourceResponse** object. For the sample code, see [onHttpErrorReceive](#onhttperrorreceive).
E
ester.zhou 已提交
2988

2989
### getReasonMessage
E
ester.zhou 已提交
2990

2991
getReasonMessage(): string
E
ester.zhou 已提交
2992

2993
Obtains the status code description of the resource response.
E
ester.zhou 已提交
2994

2995
**Return value**
E
ester.zhou 已提交
2996

2997 2998 2999
| Type    | Description           |
| ------ | ------------- |
| string | Status code description of the resource response.|
E
ester.zhou 已提交
3000

3001
### getResponseCode
E
ester.zhou 已提交
3002

3003
getResponseCode(): number
E
ester.zhou 已提交
3004

3005
Obtains the status code of the resource response.
E
ester.zhou 已提交
3006

3007
**Return value**
E
ester.zhou 已提交
3008

3009 3010 3011
| Type    | Description         |
| ------ | ----------- |
| number | Status code of the resource response.|
E
ester.zhou 已提交
3012

3013
### getResponseData
E
ester.zhou 已提交
3014

3015
getResponseData(): string
E
ester.zhou 已提交
3016

3017
Obtains the data in the resource response.
E
ester.zhou 已提交
3018

3019
**Return value**
E
ester.zhou 已提交
3020

3021 3022 3023
| Type    | Description       |
| ------ | --------- |
| string | Data in the resource response.|
E
ester.zhou 已提交
3024

3025
### getResponseEncoding
E
ester.zhou 已提交
3026

3027 3028 3029 3030 3031
getResponseEncoding(): string

Obtains the encoding string of the resource response.

**Return value**
E
ester.zhou 已提交
3032

3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043
| Type    | Description        |
| ------ | ---------- |
| string | Encoding string of the resource response.|

### getResponseHeader

getResponseHeader() : Array\<Header\>

Obtains the resource response header.

**Return value**
E
ester.zhou 已提交
3044

3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055
| Type                        | Description      |
| -------------------------- | -------- |
| Array\<[Header](#header)\> | Resource response header.|

### getResponseMimeType

getResponseMimeType(): string

Obtains the MIME type of the resource response.

**Return value**
E
ester.zhou 已提交
3056

3057 3058 3059 3060 3061 3062
| Type    | Description                |
| ------ | ------------------ |
| string | MIME type of the resource response.|

### setResponseData<sup>9+</sup>

E
ester.zhou 已提交
3063
setResponseData(data: string | number)
3064 3065 3066 3067

Sets the data in the resource response.

**Parameters**
E
ester.zhou 已提交
3068

E
ester.zhou 已提交
3069 3070 3071
| Name| Type        | Mandatory| Default Value| Description                                                    |
| ------ | ---------------- | ---- | ------ | ------------------------------------------------------------ |
| data   | string \| number | Yes  | -      | Resource response data to set. When set to a number, the value indicates a file handle.|
3072 3073 3074 3075 3076 3077 3078 3079

### setResponseEncoding<sup>9+</sup>

setResponseEncoding(encoding: string)

Sets the encoding string of the resource response.

**Parameters**
E
ester.zhou 已提交
3080

3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091
| Name     | Type  | Mandatory  | Default Value | Description        |
| -------- | ------ | ---- | ---- | ------------ |
| encoding | string | Yes   | -    | Encoding string to set.|

### setResponseMimeType<sup>9+</sup>

setResponseMimeType(mimeType: string)

Sets the MIME type of the resource response.

**Parameters**
E
ester.zhou 已提交
3092

3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103
| Name     | Type  | Mandatory  | Default Value | Description                |
| -------- | ------ | ---- | ---- | -------------------- |
| mimeType | string | Yes   | -    | MIME type to set.|

### setReasonMessage<sup>9+</sup>

setReasonMessage(reason: string)

Sets the status code description of the resource response.

**Parameters**
E
ester.zhou 已提交
3104

3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115
| Name   | Type  | Mandatory  | Default Value | Description           |
| ------ | ------ | ---- | ---- | --------------- |
| reason | string | Yes   | -    | Status code description to set.|

### setResponseHeader<sup>9+</sup>

setResponseHeader(header: Array\<Header\>)

Sets the resource response header.

**Parameters**
E
ester.zhou 已提交
3116

3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127
| Name   | Type                      | Mandatory  | Default Value | Description      |
| ------ | -------------------------- | ---- | ---- | ---------- |
| header | Array\<[Header](#header)\> | Yes   | -    | Resource response header to set.|

### setResponseCode<sup>9+</sup>

setResponseCode(code: number)

Sets the status code of the resource response.

**Parameters**
E
ester.zhou 已提交
3128

3129 3130 3131 3132
| Name | Type  | Mandatory  | Default Value | Description         |
| ---- | ------ | ---- | ---- | ------------- |
| code | number | Yes   | -    | Status code to set.|

E
ester.zhou 已提交
3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144
### setResponseIsReady<sup>9+</sup>

setResponseIsReady(IsReady: boolean)

Sets whether the resource response data is ready.

**Parameters**

| Name | Type| Mandatory| Default Value| Description                  |
| ------- | -------- | ---- | ------ | -------------------------- |
| IsReady | boolean  | Yes  | true   | Whether the resource response data is ready.|

3145 3146
## FileSelectorResult<sup>9+</sup>

E
esterzhou 已提交
3147
Notifies the **\<Web>** component of the file selection result. For the sample code, see [onShowFileSelector](#onshowfileselector9).
3148 3149 3150 3151 3152 3153 3154 3155

### handleFileList<sup>9+</sup>

handleFileList(fileList: Array\<string\>): void

Instructs the **\<Web>** component to select a file.

**Parameters**
E
ester.zhou 已提交
3156

3157 3158 3159 3160 3161 3162
| Name     | Type           | Mandatory  | Default Value | Description        |
| -------- | --------------- | ---- | ---- | ------------ |
| fileList | Array\<string\> | Yes   | -    | List of files to operate.|

## FileSelectorParam<sup>9+</sup>

E
esterzhou 已提交
3163
Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9).
3164 3165 3166 3167 3168 3169 3170 3171

### getTitle<sup>9+</sup>

getTitle(): string

Obtains the title of the file selector.

**Return value**
E
ester.zhou 已提交
3172

3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183
| Type    | Description        |
| ------ | ---------- |
| string | Title of the file selector.|

### getMode<sup>9+</sup>

getMode(): FileSelectorMode

Obtains the mode of the file selector.

**Return value**
E
ester.zhou 已提交
3184

3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195
| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [FileSelectorMode](#fileselectormode)| Mode of the file selector.|

### getAcceptType<sup>9+</sup>

getAcceptType(): Array\<string\>

Obtains the file filtering type.

**Return value**
E
ester.zhou 已提交
3196

3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207
| Type             | Description       |
| --------------- | --------- |
| Array\<string\> | File filtering type.|

### isCapture<sup>9+</sup>

isCapture(): boolean

Checks whether multimedia capabilities are invoked.

**Return value**
E
ester.zhou 已提交
3208

3209 3210 3211 3212 3213 3214
| Type     | Description          |
| ------- | ------------ |
| boolean | Whether multimedia capabilities are invoked.|

## HttpAuthHandler<sup>9+</sup>

E
esterzhou 已提交
3215
Implements the **HttpAuthHandler** object. For the sample code, see [onHttpAuthRequest](#onhttpauthrequest9).
3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236

### cancel<sup>9+</sup>

cancel(): void

Cancels HTTP authentication as requested by the user.

### confirm<sup>9+</sup>

confirm(userName: string, pwd: string): boolean

Performs HTTP authentication with the user name and password provided by the user.

**Parameters**

| Name     | Type  | Mandatory  | Default Value | Description      |
| -------- | ------ | ---- | ---- | ---------- |
| userName | string | Yes   | -    | HTTP authentication user name.|
| pwd      | string | Yes   | -    | HTTP authentication password. |

**Return value**
E
ester.zhou 已提交
3237

3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|

### isHttpAuthInfoSaved<sup>9+</sup>

isHttpAuthInfoSaved(): boolean

Uses the password cached on the server for authentication.

**Return value**
E
ester.zhou 已提交
3249

3250 3251 3252 3253
| Type     | Description                       |
| ------- | ------------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|

E
ester.zhou 已提交
3254
## SslErrorHandler<sup>9+</sup>
3255

E
esterzhou 已提交
3256
Implements an **SslErrorHandler** object. For the sample code, see [onSslErrorEventReceive Event](#onsslerroreventreceive9).
3257

E
ester.zhou 已提交
3258
### handleCancel<sup>9+</sup>
3259

E
ester.zhou 已提交
3260
handleCancel(): void
3261

E
ester.zhou 已提交
3262
Cancels this request.
3263

E
ester.zhou 已提交
3264
### handleConfirm<sup>9+</sup>
3265

E
ester.zhou 已提交
3266
handleConfirm(): void
3267

E
ester.zhou 已提交
3268
Continues using the SSL certificate.
E
ester.zhou 已提交
3269 3270 3271

## ClientAuthenticationHandler<sup>9+</sup>

E
esterzhou 已提交
3272
Implements a **ClientAuthenticationHandler** object returned by the **\<Web>** component. For the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9).
E
ester.zhou 已提交
3273 3274 3275 3276 3277

### confirm<sup>9+</sup>

confirm(priKeyFile : string, certChainFile : string): void

E
ester.zhou 已提交
3278
Uses the specified private key and client certificate chain.
E
ester.zhou 已提交
3279 3280 3281

**Parameters**

E
ester.zhou 已提交
3282 3283 3284 3285
| Name          | Type  | Mandatory  | Description              |
| ------------- | ------ | ---- | ------------------ |
| priKeyFile    | string | Yes   | File that stores the private key, which is a directory including the file name. |
| certChainFile | string | Yes   | File that stores the certificate chain, which is a directory including the file name.|
E
ester.zhou 已提交
3286 3287 3288 3289 3290

### cancel<sup>9+</sup>

cancel(): void

E
ester.zhou 已提交
3291
Cancels the client certificate request sent by the same host and port server. No additional event will be reported for requests from the same host and port server.
E
ester.zhou 已提交
3292 3293 3294 3295 3296

### ignore<sup>9+</sup>

ignore(): void

E
ester.zhou 已提交
3297
Ignores this request.
E
ester.zhou 已提交
3298 3299 3300

## PermissionRequest<sup>9+</sup>

E
esterzhou 已提交
3301
Implements the **PermissionRequest** object. For the sample code, see [onPermissionRequest](#onpermissionrequest9).
E
ester.zhou 已提交
3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313

### deny<sup>9+</sup>

deny(): void

Denies the permission requested by the web page.

### getOrigin<sup>9+</sup>

getOrigin(): string

Obtains the origin of this web page.
3314 3315 3316

**Return value**

E
ester.zhou 已提交
3317 3318 3319
| Type    | Description          |
| ------ | ------------ |
| string | Origin of the web page that requests the permission.|
3320 3321 3322 3323 3324 3325 3326 3327 3328

### getAccessibleResource<sup>9+</sup>

getAccessibleResource(): Array\<string\>

Obtains the list of accessible resources requested for the web page. For details about the resource types, see [ProtectedResourceType](#protectedresourcetype9).

**Return value**

E
ester.zhou 已提交
3329 3330
| Type             | Description           |
| --------------- | ------------- |
3331 3332 3333 3334 3335 3336 3337 3338 3339 3340
| Array\<string\> | List of accessible resources requested by the web page.|

### grant<sup>9+</sup>

grant(resources: Array\<string\>): void

Grants the permission for resources requested by the web page.

**Parameters**

E
ester.zhou 已提交
3341 3342
| Name      | Type           | Mandatory  | Default Value | Description         |
| --------- | --------------- | ---- | ---- | ------------- |
E
ester.zhou 已提交
3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378
| resources | Array\<string\> | Yes   | -    | List of resources that can be requested by the web page with the permission to grant.|

## ContextMenuSourceType<sup>9+</sup>
| Name                  | Description        |
| -------------------- | ---------- |
| None        | Other event sources. |
| Mouse       | Mouse event. |
| LongPress   | Long press event. |

## ContextMenuMediaType<sup>9+</sup>

| Name          | Description         |
| ------------ | ----------- |
| None      | Non-special media or other media types.|
| Image     | Image.    |

## ContextMenuInputFieldType<sup>9+</sup>

| Name          | Description         |
| ------------ | ----------- |
| None      | Non-input field.      |
| PlainText | Plain text field, such as the text, search, or email field.  |
| Password  | Password field.    |
| Number    | Numeric field.    |
| Telephone | Phone number field.|
| Other     | Field of any other type.    |

## ContextMenuEditStateFlags<sup>9+</sup>

| Name        | Description        |
| ------------ | ----------- |
| NONE         | Editing is not allowed.  |
| CAN_CUT      | The cut operation is allowed.  |
| CAN_COPY     | The copy operation is allowed.  |
| CAN_PASTE    | The paste operation is allowed.  |
| CAN_SELECT_ALL  | The select all operation is allowed.|
E
ester.zhou 已提交
3379

E
ester.zhou 已提交
3380 3381
## WebContextMenuParam<sup>9+</sup>

E
ester.zhou 已提交
3382
Implements a context menu, which is displayed after the user clicks the right mouse button or long presses a specific element, such as an image or a link. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
E
ester.zhou 已提交
3383 3384 3385 3386 3387

### x<sup>9+</sup>

x(): number

E
ester.zhou 已提交
3388
Obtains the X coordinate of the context menu.
E
ester.zhou 已提交
3389 3390 3391

**Return value**

E
ester.zhou 已提交
3392 3393
| Type    | Description                |
| ------ | ------------------ |
E
ester.zhou 已提交
3394 3395 3396 3397 3398 3399
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|

### y<sup>9+</sup>

y(): number

E
ester.zhou 已提交
3400
Obtains the Y coordinate of the context menu.
E
ester.zhou 已提交
3401 3402 3403

**Return value**

E
ester.zhou 已提交
3404 3405
| Type    | Description                |
| ------ | ------------------ |
E
ester.zhou 已提交
3406 3407 3408 3409 3410 3411 3412 3413 3414 3415
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|

### getLinkUrl<sup>9+</sup>

getLinkUrl(): string

Obtains the URL of the destination link.

**Return value**

E
ester.zhou 已提交
3416 3417
| Type    | Description                       |
| ------ | ------------------------- |
E
ester.zhou 已提交
3418
| string | If it is a link that is being long pressed, the URL that has passed the security check is returned.|
E
ester.zhou 已提交
3419

E
esterzhou 已提交
3420
### getUnfilteredLinkUrl<sup>9+</sup>
E
ester.zhou 已提交
3421

E
esterzhou 已提交
3422
getUnfilteredLinkUrl(): string
E
ester.zhou 已提交
3423 3424 3425 3426 3427

Obtains the URL of the destination link.

**Return value**

E
ester.zhou 已提交
3428 3429
| Type    | Description                   |
| ------ | --------------------- |
E
ester.zhou 已提交
3430
| string | If it is a link that is being long pressed, the original URL is returned.|
E
ester.zhou 已提交
3431 3432 3433 3434 3435 3436 3437 3438 3439

### getSourceUrl<sup>9+</sup>

getSourceUrl(): string

Obtain the source URL.

**Return value**

E
ester.zhou 已提交
3440 3441
| Type    | Description                      |
| ------ | ------------------------ |
E
ester.zhou 已提交
3442 3443 3444 3445 3446 3447 3448 3449 3450 3451
| string | If the selected element has the **src** attribute, the URL in the **src** is returned.|

### existsImageContents<sup>9+</sup>

existsImageContents(): boolean

Checks whether image content exists.

**Return value**

E
ester.zhou 已提交
3452 3453
| Type     | Description                       |
| ------- | ------------------------- |
E
ester.zhou 已提交
3454 3455
| boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.|

E
ester.zhou 已提交
3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527
### getMediaType<sup>9+</sup>

getMediaType(): ContextMenuMediaType

Obtains the media type of this web page element.

**Return value**

| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [ContextMenuMediaType](#contextmenumediatype9) | Media type of the web page element.|

### getSelectionText<sup>9+</sup>

getSelectionText(): string

Obtains the selected text.

**Return value**

| Type     | Description                       |
| ------- | ------------------------- |
| string | Selected text for the context menu. If no text is selected, null is returned.|

### getSourceType<sup>9+</sup>

getSourceType(): ContextMenuSourceType

Obtains the event source of the context menu.

**Return value**

| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [ContextMenuSourceType](#contextmenusourcetype9) | Event source of the context menu.|

### getInputFieldType<sup>9+</sup>

getInputFieldType(): ContextMenuInputFieldType

Obtains the input field type of this web page element.

**Return value**

| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [ContextMenuInputFieldType](#contextmenuinputfieldtype9) | Input field type.|

### isEditable<sup>9+</sup>

isEditable(): boolean

Checks whether this web page element is editable.

**Return value**

| Type     | Description                       |
| ------- | ------------------------- |
| boolean | Returns **true** if the web page element is editable; returns **false** otherwise.|

### getEditStateFlags<sup>9+</sup>

getEditStateFlags(): number

Obtains the edit state flag of this web page element.

**Return value**

| Type     | Description                       |
| ------- | ------------------------- |
| number | Edit state flag of the web page element. For details, see [ContextMenuEditStateFlags](#contextmenueditstateflags9).|

E
ester.zhou 已提交
3528 3529
## WebContextMenuResult<sup>9+</sup>

E
ester.zhou 已提交
3530
Implements a **WebContextMenuResult** object. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
E
ester.zhou 已提交
3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543

### closeContextMenu<sup>9+</sup>

closeContextMenu(): void

Closes this context menu. This API must be called when no operations in **WebContextMenuResult** are performed.

### copyImage<sup>9+</sup>

copyImage(): void

Copies the image specified in **WebContextMenuParam**.

E
ester.zhou 已提交
3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567
### copy<sup>9+</sup>

copy(): void

Performs the copy operation related to this context menu.

### paste<sup>9+</sup>

paste(): void

Performs the paste operation related to this context menu.

### cut<sup>9+</sup>

cut(): void

Performs the cut operation related to this context menu.

### selectAll<sup>9+</sup>

selectAll(): void

Performs the select all operation related to this context menu.

E
ester.zhou 已提交
3568 3569
## JsGeolocation

E
esterzhou 已提交
3570
Implements the **PermissionRequest** object. For the sample code, see [onGeolocationShow Event](#ongeolocationshow).
E
ester.zhou 已提交
3571 3572 3573 3574 3575 3576 3577 3578 3579

### invoke

invoke(origin: string, allow: boolean, retain: boolean): void

Sets the geolocation permission status of a web page.

**Parameters**

E
ester.zhou 已提交
3580 3581 3582 3583
| Name   | Type   | Mandatory  | Default Value | Description                                    |
| ------ | ------- | ---- | ---- | ---------------------------------------- |
| origin | string  | Yes   | -    | Index of the origin.                              |
| allow  | boolean | Yes   | -    | Geolocation permission status.                            |
E
ester.zhou 已提交
3584
| retain | boolean | Yes   | -    | Whether the geolocation permission status can be saved to the system. You can manage the geolocation permissions saved to the system through [GeolocationPermissions<sup>9+</sup>](../apis/js-apis-webview.md#geolocationpermissions).|
E
ester.zhou 已提交
3585

E
ester.zhou 已提交
3586 3587
## WebController

E
esterzhou 已提交
3588
Implements a **WebController** to control the behavior of the **\<Web>** component. A **WebController** can control only one **\<Web>** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **\<Web>** component.
E
ester.zhou 已提交
3589

E
ester.zhou 已提交
3590 3591
This API is deprecated since API version 9. You are advised to use [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller).

E
ester.zhou 已提交
3592 3593 3594 3595 3596 3597
### Creating an Object

```
webController: WebController = new WebController()
```

E
ester.zhou 已提交
3598
### requestFocus<sup>(deprecated)</sup>
3599 3600 3601 3602 3603

requestFocus()

Requests focus for this web page.

E
ester.zhou 已提交
3604 3605
This API is deprecated since API version 9. You are advised to use [requestFocus<sup>9+</sup>](../apis/js-apis-webview.md#requestfocus).

3606
**Example**
E
ester.zhou 已提交
3607

3608 3609 3610 3611 3612
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3613
    controller: WebController = new WebController()
3614 3615 3616 3617 3618
  
    build() {
      Column() {
        Button('requestFocus')
          .onClick(() => {
E
ester.zhou 已提交
3619
            this.controller.requestFocus()
3620 3621 3622 3623 3624 3625 3626
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3627
### accessBackward<sup>(deprecated)</sup>
E
ester.zhou 已提交
3628 3629 3630 3631 3632

accessBackward(): boolean

Checks whether going to the previous page can be performed on the current page.

E
ester.zhou 已提交
3633 3634
This API is deprecated since API version 9. You are advised to use [accessBackward<sup>9+</sup>](../apis/js-apis-webview.md#accessbackward).

3635
**Return value**
E
ester.zhou 已提交
3636

3637 3638 3639 3640 3641
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if going to the previous page can be performed on the current page; returns **false** otherwise.|

**Example**
E
ester.zhou 已提交
3642

3643 3644 3645 3646 3647
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3648
    controller: WebController = new WebController()
3649 3650 3651 3652 3653
  
    build() {
      Column() {
        Button('accessBackward')
          .onClick(() => {
E
ester.zhou 已提交
3654 3655
            let result = this.controller.accessBackward()
            console.log('result:' + result)
3656 3657 3658 3659 3660 3661 3662
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3663
### accessForward<sup>(deprecated)</sup>
E
ester.zhou 已提交
3664 3665 3666 3667 3668

accessForward(): boolean

Checks whether going to the next page can be performed on the current page.

E
ester.zhou 已提交
3669 3670
This API is deprecated since API version 9. You are advised to use [accessForward<sup>9+</sup>](../apis/js-apis-webview.md#accessforward).

3671
**Return value**
E
ester.zhou 已提交
3672

3673 3674 3675 3676 3677
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if going to the next page can be performed on the current page; returns **false** otherwise.|

**Example**
E
ester.zhou 已提交
3678

3679 3680 3681 3682 3683
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3684
    controller: WebController = new WebController()
3685 3686 3687 3688 3689
  
    build() {
      Column() {
        Button('accessForward')
          .onClick(() => {
E
ester.zhou 已提交
3690 3691
            let result = this.controller.accessForward()
            console.log('result:' + result)
3692 3693 3694 3695 3696 3697 3698
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3699
### accessStep<sup>(deprecated)</sup>
E
ester.zhou 已提交
3700 3701 3702

accessStep(step: number): boolean

E
ester.zhou 已提交
3703
Performs a specific number of steps forward or backward from the current page.
E
ester.zhou 已提交
3704

E
ester.zhou 已提交
3705 3706
This API is deprecated since API version 9. You are advised to use [accessStep<sup>9+</sup>](../apis/js-apis-webview.md#accessstep).

3707 3708 3709 3710
**Parameters**

| Name | Type  | Mandatory  | Default Value | Description                 |
| ---- | ------ | ---- | ---- | --------------------- |
E
ester.zhou 已提交
3711
| step | number | Yes   | -    | Number of the steps to take. A positive number means to go forward, and a negative number means to go backward.|
3712 3713

**Return value**
E
ester.zhou 已提交
3714

3715 3716
| Type     | Description       |
| ------- | --------- |
E
ester.zhou 已提交
3717
| boolean | Whether going forward or backward from the current page is successful.|
3718 3719

**Example**
E
ester.zhou 已提交
3720

3721 3722 3723 3724 3725
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3726 3727
    controller: WebController = new WebController()
    @State steps: number = 2
3728 3729 3730 3731 3732
  
    build() {
      Column() {
        Button('accessStep')
          .onClick(() => {
E
ester.zhou 已提交
3733 3734
            let result = this.controller.accessStep(this.steps)
            console.log('result:' + result)
3735 3736 3737 3738 3739 3740
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
3741

E
ester.zhou 已提交
3742
### backward<sup>(deprecated)</sup>
E
ester.zhou 已提交
3743 3744 3745 3746 3747

backward(): void

Goes to the previous page based on the history stack. This API is generally used together with **accessBackward**.

E
ester.zhou 已提交
3748 3749
This API is deprecated since API version 9. You are advised to use [backward<sup>9+</sup>](../apis/js-apis-webview.md#backward).

3750
**Example**
E
ester.zhou 已提交
3751

3752 3753 3754 3755 3756
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3757
    controller: WebController = new WebController()
3758 3759 3760 3761 3762
  
    build() {
      Column() {
        Button('backward')
          .onClick(() => {
E
ester.zhou 已提交
3763
            this.controller.backward()
3764 3765 3766 3767 3768 3769
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
3770

E
ester.zhou 已提交
3771
### forward<sup>(deprecated)</sup>
E
ester.zhou 已提交
3772 3773 3774 3775 3776

forward(): void

Goes to the next page based on the history stack. This API is generally used together with **accessForward**.

E
ester.zhou 已提交
3777 3778
This API is deprecated since API version 9. You are advised to use [forward<sup>9+</sup>](../apis/js-apis-webview.md#forward).

3779
**Example**
E
ester.zhou 已提交
3780

3781 3782 3783 3784 3785
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3786
    controller: WebController = new WebController()
3787 3788 3789 3790 3791
  
    build() {
      Column() {
        Button('forward')
          .onClick(() => {
E
ester.zhou 已提交
3792
            this.controller.forward()
3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### backOrForward<sup>9+</sup>

backOrForward(step: number): void

Performs a specific number of steps forward or backward on the current page based on the history stack. No redirection will be performed if the corresponding page does not exist in the history stack.

**Parameters**
E
ester.zhou 已提交
3807

3808 3809 3810 3811 3812
| Name | Type  | Mandatory  | Default Value | Description       |
| ---- | ------ | ---- | ---- | ----------- |
| step | number | Yes   | -    | Number of the steps to take.|

**Example**
E
ester.zhou 已提交
3813

3814 3815 3816 3817 3818
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3819 3820
    controller: WebController = new WebController()
    @State step: number = -2
E
ester.zhou 已提交
3821
  
3822 3823 3824
    build() {
      Column() {
        Button('backOrForward')
E
ester.zhou 已提交
3825
          .onClick(() => {
E
ester.zhou 已提交
3826
            this.controller.backOrForward(this.step)
E
ester.zhou 已提交
3827 3828 3829
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
3830 3831 3832 3833
    }
  }
  ```

E
ester.zhou 已提交
3834
### deleteJavaScriptRegister<sup>(deprecated)</sup>
3835 3836 3837 3838 3839

deleteJavaScriptRegister(name: string)

Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the [refresh](#refresh) API.

E
ester.zhou 已提交
3840 3841
This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](../apis/js-apis-webview.md#deletejavascriptregister).

3842
**Parameters**
E
ester.zhou 已提交
3843

3844 3845 3846 3847 3848
| Name | Type  | Mandatory  | Default Value | Description                                    |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
| name | string | Yes   | -    | Name of the registered JavaScript object, which can be used to invoke the corresponding object on the application side from the web side.|

**Example**
E
ester.zhou 已提交
3849

3850 3851 3852 3853 3854
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3855 3856
    controller: WebController = new WebController()
    @State name: string = 'Object'
3857 3858 3859 3860 3861
  
    build() {
      Column() {
        Button('deleteJavaScriptRegister')
          .onClick(() => {
E
ester.zhou 已提交
3862
            this.controller.deleteJavaScriptRegister(this.name)
3863 3864 3865 3866 3867 3868 3869
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3870
### getHitTest<sup>(deprecated)</sup>
E
ester.zhou 已提交
3871 3872 3873 3874 3875

getHitTest(): HitTestType

Obtains the element type of the area being clicked.	

E
ester.zhou 已提交
3876 3877
This API is deprecated since API version 9. You are advised to use [getHitTest<sup>9+</sup>](../apis/js-apis-webview.md#gethittest).

3878
**Return value**
E
ester.zhou 已提交
3879

3880 3881 3882 3883 3884
| Type                             | Description         |
| ------------------------------- | ----------- |
| [HitTestType](#hittesttype)| Element type of the area being clicked.|

**Example**
E
ester.zhou 已提交
3885

3886 3887 3888 3889 3890
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3891
    controller: WebController = new WebController()
3892 3893 3894 3895 3896
  
    build() {
      Column() {
        Button('getHitTest')
          .onClick(() => {
E
ester.zhou 已提交
3897 3898
            let hitType = this.controller.getHitTest()
            console.log("hitType: " + hitType)
3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getHitTestValue<sup>9+</sup>
getHitTestValue(): HitTestValue

Obtains the element information of the area being clicked.

**Return value**
E
ester.zhou 已提交
3912

3913 3914 3915 3916 3917
| Type                            | Description        |
| ------------------------------ | ---------- |
| [HitTestValue](#hittestvalue9) | Element information of the area being clicked.|

**Example**
E
ester.zhou 已提交
3918

3919 3920 3921 3922 3923
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3924
    controller: WebController = new WebController()
3925 3926 3927 3928 3929
  
    build() {
      Column() {
        Button('getHitTestValue')
          .onClick(() => {
E
ester.zhou 已提交
3930 3931 3932
            let hitValue = this.controller.getHitTestValue()
            console.log("hitType: " + hitValue.getType())
            console.log("extra: " + hitValue.getExtra())
3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getWebId<sup>9+</sup>
getWebId(): number

Obtains the index value of this **\<Web>** component, which can be used for **\<Web>** component management.

**Return value**
E
ester.zhou 已提交
3946

3947 3948 3949 3950 3951
| Type    | Description          |
| ------ | ------------ |
| number | Index value of the current **\<Web>** component.|

**Example**
E
ester.zhou 已提交
3952

3953 3954 3955 3956 3957
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3958
    controller: WebController = new WebController()
3959 3960 3961 3962 3963
  
    build() {
      Column() {
        Button('getWebId')
          .onClick(() => {
E
ester.zhou 已提交
3964 3965
            let id = this.controller.getWebId()
            console.log("id: " + id)
3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getTitle<sup>9+</sup>
getTitle(): string

Obtains the title of the current web page.

**Return value**
E
ester.zhou 已提交
3979

3980 3981 3982 3983 3984
| Type    | Description      |
| ------ | -------- |
| string | Title of the current web page.|

**Example**
E
ester.zhou 已提交
3985

3986 3987 3988 3989 3990
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
3991
    controller: WebController = new WebController()
3992 3993 3994 3995 3996
  
    build() {
      Column() {
        Button('getTitle')
          .onClick(() => {
E
ester.zhou 已提交
3997 3998
            let title = this.controller.getTitle()
            console.log("title: " + title)
3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getPageHeight<sup>9+</sup>
getPageHeight(): number

Obtains the height of the current web page.

**Return value**
E
ester.zhou 已提交
4012

4013 4014 4015 4016 4017
| Type    | Description        |
| ------ | ---------- |
| number | Height of the current web page.|

**Example**
E
ester.zhou 已提交
4018

4019 4020 4021 4022 4023
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4024
    controller: WebController = new WebController()
4025 4026 4027 4028 4029
  
    build() {
      Column() {
        Button('getPageHeight')
          .onClick(() => {
E
ester.zhou 已提交
4030 4031
            let pageHeight = this.controller.getPageHeight()
            console.log("pageHeight: " + pageHeight)
4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getDefaultUserAgent<sup>9+</sup>
getDefaultUserAgent(): string

Obtains the default user agent of the current web page.

**Return value**
E
ester.zhou 已提交
4045

4046 4047 4048 4049 4050
| Type    | Description     |
| ------ | ------- |
| string | Default user agent.|

**Example**
E
ester.zhou 已提交
4051

4052 4053 4054 4055 4056
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4057
    controller: WebController = new WebController()
4058 4059 4060 4061 4062
  
    build() {
      Column() {
        Button('getDefaultUserAgent')
          .onClick(() => {
E
ester.zhou 已提交
4063 4064
            let userAgent = this.controller.getDefaultUserAgent()
            console.log("userAgent: " + userAgent)
4065 4066 4067 4068 4069 4070
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4071

E
ester.zhou 已提交
4072
### loadData<sup>(deprecated)</sup>
E
ester.zhou 已提交
4073

4074
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
E
ester.zhou 已提交
4075 4076 4077

Loads data. If **baseUrl** is empty, the specified character string will be loaded using the data protocol.

E
ester.zhou 已提交
4078
If **baseUrl** is set to a data URL, the encoded string will be loaded by the **\<Web>** component using the data protocol.
E
ester.zhou 已提交
4079

E
ester.zhou 已提交
4080
If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be processed by the **\<Web>** component as a non-encoded string in a manner similar to **loadUrl**.
E
ester.zhou 已提交
4081

E
ester.zhou 已提交
4082 4083
This API is deprecated since API version 9. You are advised to use [loadData<sup>9+</sup>](../apis/js-apis-webview.md#loaddata).

4084
**Parameters**
E
ester.zhou 已提交
4085

4086 4087 4088 4089 4090 4091 4092 4093 4094
| Name       | Type  | Mandatory  | Default Value | Description                                    |
| ---------- | ------ | ---- | ---- | ---------------------------------------- |
| data       | string | Yes   | -    | Character string obtained after being Base64 or URL encoded.             |
| mimeType   | string | Yes   | -    | Media type (MIME).                             |
| encoding   | string | Yes   | -    | Encoding type, which can be Base64 or URL.               |
| baseUrl    | string | No   | -    | URL (HTTP/HTTPS/data compliant), which is assigned by the **\<Web>** component to **window.origin**.|
| historyUrl | string | No   | -    | Historical record URL. If this parameter is not empty, it can be managed in historical records to implement page going backward and forward. This parameter is invalid when **baseUrl** is left empty.|

**Example**
E
ester.zhou 已提交
4095

4096 4097 4098 4099 4100
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4101
    controller: WebController = new WebController()
4102 4103 4104 4105 4106 4107 4108 4109 4110
  
    build() {
      Column() {
        Button('loadData')
          .onClick(() => {
            this.controller.loadData({
              data: "<html><body bgcolor=\"white\">Source:<pre>source</pre></body></html>",
              mimeType: "text/html",
              encoding: "UTF-8"
E
ester.zhou 已提交
4111
            })
4112 4113 4114 4115 4116 4117
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4118

E
ester.zhou 已提交
4119
### loadUrl<sup>(deprecated)</sup>
E
ester.zhou 已提交
4120

4121
loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
E
ester.zhou 已提交
4122 4123 4124 4125 4126

Loads a URL using the specified HTTP header.

The object injected through **loadUrl** is valid only in the current document. It will be invalid on a new page navigated to through **loadUrl**.

4127 4128
The object injected through **registerJavaScriptProxy** is still valid on a new page redirected through **loadUrl**.

E
ester.zhou 已提交
4129 4130
This API is deprecated since API version 9. You are advised to use [loadUrl<sup>9+</sup>](../apis/js-apis-webview.md#loadurl).

4131
**Parameters**
E
ester.zhou 已提交
4132

4133 4134 4135 4136 4137 4138
| Name    | Type                      | Mandatory  | Default Value | Description          |
| ------- | -------------------------- | ---- | ---- | -------------- |
| url     | string                     | Yes   | -    | URL to load.    |
| headers | Array\<[Header](#header)\> | No   | []   | Additional HTTP request header of the URL.|

**Example**
E
ester.zhou 已提交
4139

4140 4141 4142 4143 4144
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4145
    controller: WebController = new WebController()
4146 4147 4148 4149 4150
  
    build() {
      Column() {
        Button('loadUrl')
          .onClick(() => {
E
ester.zhou 已提交
4151
            this.controller.loadUrl({ url: 'www.example.com' })
4152 4153 4154 4155 4156 4157
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4158

E
ester.zhou 已提交
4159
### onActive<sup>(deprecated)</sup>
E
ester.zhou 已提交
4160 4161 4162

onActive(): void

E
ester.zhou 已提交
4163
Invoked when the **\<Web>** component enters the active state.
E
ester.zhou 已提交
4164

E
ester.zhou 已提交
4165 4166
This API is deprecated since API version 9. You are advised to use [onActive<sup>9+</sup>](../apis/js-apis-webview.md#onactive).

4167
**Example**
E
ester.zhou 已提交
4168

4169 4170 4171 4172 4173
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4174
    controller: WebController = new WebController()
4175 4176 4177 4178 4179
  
    build() {
      Column() {
        Button('onActive')
          .onClick(() => {
E
ester.zhou 已提交
4180
            this.controller.onActive()
4181 4182 4183 4184 4185 4186 4187
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4188
### onInactive<sup>(deprecated)</sup>
E
ester.zhou 已提交
4189 4190 4191

onInactive(): void

E
ester.zhou 已提交
4192
Invoked when the **\<Web>** component enters the inactive state.
E
ester.zhou 已提交
4193

E
ester.zhou 已提交
4194 4195
This API is deprecated since API version 9. You are advised to use [onInactive<sup>9+</sup>](../apis/js-apis-webview.md#oninactive).

4196
**Example**
E
ester.zhou 已提交
4197

4198 4199 4200 4201 4202
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4203
    controller: WebController = new WebController()
4204 4205 4206 4207 4208
  
    build() {
      Column() {
        Button('onInactive')
          .onClick(() => {
E
ester.zhou 已提交
4209
            this.controller.onInactive()
4210 4211 4212 4213 4214 4215 4216
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4217
### zoom<sup>(deprecated)</sup>
4218 4219 4220 4221
zoom(factor: number): void

Sets a zoom factor for the current web page.

E
ester.zhou 已提交
4222 4223
This API is deprecated since API version 9. You are advised to use [zoom<sup>9+</sup>](../apis/js-apis-webview.md#zoom).

4224
**Parameters**
E
ester.zhou 已提交
4225

4226 4227 4228 4229 4230
| Name   | Type  | Mandatory  | Description                          |
| ------ | ------ | ---- | ------------------------------ |
| factor | number | Yes   | Zoom factor to set. A positive value indicates zoom-in, and a negative value indicates zoom-out.|

**Example**
E
ester.zhou 已提交
4231

4232 4233 4234 4235 4236
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4237 4238
    controller: WebController = new WebController()
    @State factor: number = 1
4239 4240 4241 4242 4243
  
    build() {
      Column() {
        Button('zoom')
          .onClick(() => {
E
ester.zhou 已提交
4244
            this.controller.zoom(this.factor)
4245 4246 4247 4248 4249 4250 4251 4252 4253 4254
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### zoomIn<sup>9+</sup>
zoomIn(): boolean

E
ester.zhou 已提交
4255
Zooms in on this web page by 20%.
4256 4257

**Return value**
E
ester.zhou 已提交
4258

4259 4260 4261 4262 4263
| Type     | Description         |
| ------- | ----------- |
| boolean | Operation result.|

**Example**
E
ester.zhou 已提交
4264

4265 4266 4267 4268 4269
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4270
    controller: WebController = new WebController()
4271 4272 4273 4274 4275
  
    build() {
      Column() {
        Button('zoomIn')
          .onClick(() => {
E
ester.zhou 已提交
4276 4277
            let result = this.controller.zoomIn()
            console.log("result: " + result)
4278 4279 4280 4281 4282 4283 4284 4285 4286 4287
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### zoomOut<sup>9+</sup>
zoomOut(): boolean

E
ester.zhou 已提交
4288
Zooms out of this web page by 20%.
4289 4290

**Return value**
E
ester.zhou 已提交
4291

4292 4293 4294 4295 4296
| Type     | Description         |
| ------- | ----------- |
| boolean | Operation result.|

**Example**
E
ester.zhou 已提交
4297

4298 4299 4300 4301 4302
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4303
    controller: WebController = new WebController()
4304 4305 4306 4307 4308
  
    build() {
      Column() {
        Button('zoomOut')
          .onClick(() => {
E
ester.zhou 已提交
4309 4310
            let result = this.controller.zoomOut()
            console.log("result: " + result)
4311 4312 4313 4314 4315 4316 4317
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4318
### refresh<sup>(deprecated)</sup>
E
ester.zhou 已提交
4319

4320
refresh()
E
ester.zhou 已提交
4321

E
ester.zhou 已提交
4322
Invoked when the **\<Web>** component refreshes the web page.
E
ester.zhou 已提交
4323

E
ester.zhou 已提交
4324 4325
This API is deprecated since API version 9. You are advised to use [refresh<sup>9+</sup>](../apis/js-apis-webview.md#refresh).

4326
**Example**
E
ester.zhou 已提交
4327

4328 4329 4330 4331 4332
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4333
    controller: WebController = new WebController()
4334 4335 4336 4337 4338
  
    build() {
      Column() {
        Button('refresh')
          .onClick(() => {
E
ester.zhou 已提交
4339
            this.controller.refresh()
4340 4341 4342 4343 4344 4345
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4346

E
ester.zhou 已提交
4347
### registerJavaScriptProxy<sup>(deprecated)</sup>
E
ester.zhou 已提交
4348

4349 4350
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> })

E
ester.zhou 已提交
4351 4352 4353
Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. You must invoke the [refresh](#refresh) API for the registration to take effect.

This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](../apis/js-apis-webview.md#registerjavascriptproxy).
4354 4355

**Parameters**
E
ester.zhou 已提交
4356

4357 4358
| Name       | Type           | Mandatory  | Default Value | Description                                    |
| ---------- | --------------- | ---- | ---- | ---------------------------------------- |
E
ester.zhou 已提交
4359
| object     | object          | Yes   | -    | Application-side JavaScript object to be registered. Methods can be declared, but attributes cannot. The parameters and return value can only be of the string, number, or Boolean type.|
4360 4361 4362 4363
| name       | string          | Yes   | -    | Name of the object to be registered, which is the same as that invoked in the window. After registration, the window can use this name to access the JavaScript object at the application side.|
| methodList | Array\<string\> | Yes   | -    | Methods of the JavaScript object to be registered at the application side.                |

**Example**
E
ester.zhou 已提交
4364

4365 4366 4367 4368 4369 4370 4371 4372
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct Index {
    controller: WebController = new WebController()
    testObj = {
      test: (data) => {
E
ester.zhou 已提交
4373
        return "ArkUI Web Component"
4374 4375
      },
      toString: () => {
E
ester.zhou 已提交
4376
        console.log('Web Component toString')
4377 4378 4379 4380 4381 4382 4383 4384 4385 4386
      }
    }
    build() {
      Column() {
        Row() {
          Button('Register JavaScript To Window').onClick(() => {
            this.controller.registerJavaScriptProxy({
              object: this.testObj,
              name: "objName",
              methodList: ["test", "toString"],
E
ester.zhou 已提交
4387
            })
4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406
          })
        }
        Web({ src: $rawfile('index.html'), controller: this.controller })
          .javaScriptAccess(true)
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
      <meta charset="utf-8">
      <body>
          Hello world!
      </body>
      <script type="text/javascript">
      function htmlTest() {
E
ester.zhou 已提交
4407 4408
          str = objName.test("test function")
          console.log('objName.test result:'+ str)
4409 4410 4411 4412 4413
      }
  </script>
  </html>
  
  ```
E
ester.zhou 已提交
4414

E
ester.zhou 已提交
4415
### runJavaScript<sup>(deprecated)</sup>
E
ester.zhou 已提交
4416

4417
runJavaScript(options: { script: string, callback?: (result: string) => void })
E
ester.zhou 已提交
4418

E
ester.zhou 已提交
4419
Executes a JavaScript script. This API uses an asynchronous callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be invoked in **onPageEnd**.
E
ester.zhou 已提交
4420

E
ester.zhou 已提交
4421 4422
This API is deprecated since API version 9. You are advised to use [runJavaScript<sup>9+</sup>](../apis/js-apis-webview.md#runjavascript).

4423
**Parameters**
E
ester.zhou 已提交
4424

4425 4426 4427 4428 4429 4430
| Name     | Type                    | Mandatory  | Default Value | Description                                    |
| -------- | ------------------------ | ---- | ---- | ---------------------------------------- |
| script   | string                   | Yes   | -    | JavaScript script.                           |
| callback | (result: string) => void | No   | -    | Callback used to return the result. Returns **null** if the JavaScript script fails to be executed or no value is returned.|

**Example**
E
ester.zhou 已提交
4431

4432 4433 4434 4435 4436
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4437
    controller: WebController = new WebController()
4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449
    @State webResult: string = ''
    build() {
      Column() {
        Text(this.webResult).fontSize(20)
        Web({ src: $rawfile('index.html'), controller: this.controller })
        .javaScriptAccess(true)
        .onPageEnd(e => {
          this.controller.runJavaScript({
            script: 'test()',
            callback: (result: string)=> {
              this.webResult = result
              console.info(`The test() return value is: ${result}`)
E
ester.zhou 已提交
4450 4451
            }})
          console.info('url: ', e.url)
4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467
        })
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
    <meta charset="utf-8">
    <body>
        Hello world!
    </body>
    <script type="text/javascript">
    function test() {
E
ester.zhou 已提交
4468
        console.log('Ark WebComponent')
4469 4470 4471 4472
        return "This value is from index.html"
    }
    </script>
  </html>
E
ester.zhou 已提交
4473

4474
  ```
E
ester.zhou 已提交
4475

E
ester.zhou 已提交
4476
### stop<sup>(deprecated)</sup>
E
ester.zhou 已提交
4477

4478
stop()
E
ester.zhou 已提交
4479 4480 4481

Stops page loading.

E
ester.zhou 已提交
4482 4483
This API is deprecated since API version 9. You are advised to use [stop<sup>9+</sup>](../apis/js-apis-webview.md#stop).

4484
**Example**
E
ester.zhou 已提交
4485

4486 4487 4488 4489 4490
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4491
    controller: WebController = new WebController()
4492 4493 4494 4495 4496
  
    build() {
      Column() {
        Button('stop')
          .onClick(() => {
E
ester.zhou 已提交
4497
            this.controller.stop()
4498 4499 4500 4501 4502 4503 4504
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4505
### clearHistory<sup>(deprecated)</sup>
E
ester.zhou 已提交
4506 4507 4508 4509 4510

clearHistory(): void

Clears the browsing history.

E
ester.zhou 已提交
4511 4512
This API is deprecated since API version 9. You are advised to use [clearHistory<sup>9+</sup>](../apis/js-apis-webview.md#clearhistory).

4513
**Example**
E
ester.zhou 已提交
4514

4515 4516 4517 4518 4519
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4520
    controller: WebController = new WebController()
4521 4522 4523 4524 4525
  
    build() {
      Column() {
        Button('clearHistory')
          .onClick(() => {
E
ester.zhou 已提交
4526
            this.controller.clearHistory()
4527 4528 4529 4530 4531 4532 4533
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4534 4535 4536 4537
### clearSslCache

clearSslCache(): void

E
ester.zhou 已提交
4538
Clears the user operation corresponding to the SSL certificate error event recorded by the **\<Web>** component.
E
ester.zhou 已提交
4539 4540 4541 4542 4543 4544 4545 4546

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4547
    controller: WebController = new WebController()
E
ester.zhou 已提交
4548 4549 4550 4551 4552

    build() {
      Column() {
        Button('clearSslCache')
          .onClick(() => {
E
ester.zhou 已提交
4553
            this.controller.clearSslCache()
E
ester.zhou 已提交
4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### clearClientAuthenticationCache

clearClientAuthenticationCache(): void

E
ester.zhou 已提交
4565
Clears the user operation corresponding to the client certificate request event recorded by the **\<Web>** component.
E
ester.zhou 已提交
4566 4567 4568 4569 4570 4571 4572 4573

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4574
    controller: WebController = new WebController()
E
ester.zhou 已提交
4575 4576 4577 4578 4579

    build() {
      Column() {
        Button('clearClientAuthenticationCache')
          .onClick(() => {
E
ester.zhou 已提交
4580
            this.controller.clearClientAuthenticationCache()
E
ester.zhou 已提交
4581 4582 4583 4584 4585 4586 4587
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4588
### getCookieManager<sup>9+</sup>
E
ester.zhou 已提交
4589 4590 4591 4592

getCookieManager(): WebCookie

Obtains the cookie management object of the **\<Web>** component.
4593 4594

**Return value**
E
ester.zhou 已提交
4595

4596 4597 4598 4599 4600
| Type       | Description                                      |
| --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).|

**Example**
E
ester.zhou 已提交
4601

4602 4603 4604 4605 4606
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4607
    controller: WebController = new WebController()
4608 4609 4610 4611 4612
  
    build() {
      Column() {
        Button('getCookieManager')
          .onClick(() => {
E
ester.zhou 已提交
4613
            let cookieManager = this.controller.getCookieManager()
4614 4615 4616 4617 4618 4619 4620
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4621
### createWebMessagePorts<sup>9+</sup>
4622

E
ester.zhou 已提交
4623
createWebMessagePorts(): Array\<WebMessagePort\>
4624

E
ester.zhou 已提交
4625
Creates web message ports.
4626 4627 4628 4629

**Return value**


E
ester.zhou 已提交
4630 4631
| Type                                      | Description        |
| ---------------------------------------- | ---------- |
E
ester.zhou 已提交
4632
| Array\<[WebMessagePort](#webmessageport9)\> | List of web message ports.|
4633

E
ester.zhou 已提交
4634
**Example**
4635

E
ester.zhou 已提交
4636 4637 4638 4639 4640
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4641 4642
    controller: WebController = new WebController()
    ports: WebMessagePort[] = null
E
ester.zhou 已提交
4643 4644 4645 4646
    build() {
      Column() {
        Button('createWebMessagePorts')
          .onClick(() => {
E
ester.zhou 已提交
4647
            this.ports = this.controller.createWebMessagePorts()
E
ester.zhou 已提交
4648 4649 4650 4651 4652 4653 4654
            console.log("createWebMessagePorts size:" + this.ports.length)
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
4655

E
ester.zhou 已提交
4656
### postMessage<sup>9+</sup>
4657

E
ester.zhou 已提交
4658
postMessage(options: { message: WebMessageEvent, uri: string}): void
E
ester.zhou 已提交
4659

E
ester.zhou 已提交
4660
Sends a web message to an HTML5 window.
4661 4662 4663

**Parameters**

E
ester.zhou 已提交
4664 4665 4666 4667
| Name    | Type                                | Mandatory  | Default Value | Description             |
| ------- | ------------------------------------ | ---- | ---- | ----------------- |
| message | [WebMessageEvent](#webmessageevent9) | Yes   | -    | Message to send, including the data and message port.|
| uri     | string                               | Yes   | -    | URI for receiving the message.       |
4668 4669

**Example**
E
ester.zhou 已提交
4670

4671
  ```ts
E
ester.zhou 已提交
4672
  // index.ets
4673 4674 4675
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4676 4677 4678 4679 4680
    controller: WebController = new WebController()
    ports: WebMessagePort[] = null
    @State sendFromEts: string = 'Send this message from ets to HTML'
    @State receivedFromHtml: string = 'Display received message send from HTML'

4681 4682
    build() {
      Column() {
E
ester.zhou 已提交
4683 4684 4685 4686 4687 4688 4689 4690 4691 4692
        // Display the received HTML content.
        Text(this.receivedFromHtml)
        // Send the content in the text box to an HTML window.
        TextInput({placeholder: 'Send this message from ets to HTML'})
        .onChange((value: string) => {
          this.sendFromEts = value
        })

        // 1. Create two message ports.
        Button('1.CreateWebMessagePorts')
4693
          .onClick(() => {
E
ester.zhou 已提交
4694 4695
            this.ports = this.controller.createWebMessagePorts()
            console.log("createWebMessagePorts size:" + this.ports.length)
4696
          })
E
ester.zhou 已提交
4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726

        // 2. Send one of the message ports to the HTML side, which can then save and use the port.
        Button('2.PostMessagePort')
          .onClick(() => {
            var sendPortArray = new Array(this.ports[1])
            var msgEvent = new WebMessageEvent()
            msgEvent.setData("__init_port__")
            msgEvent.setPorts(sendPortArray)
            this.controller.postMessage({message: msgEvent, uri: "*"})
          })

        // 3. Register a callback for the other message port on the application side.
        Button('3.RegisterCallback')
          .onClick(() => {
              this.ports[0].onMessageEvent((result: string) => {
                var msg = 'Got msg from HTML: ' + result
                this.receivedFromHtml = msg
              })
          })

        // 4. Use the port on the application side to send messages to the message port that has been sent to the HTML.
        Button('4.SendDataToHtml5')
          .onClick(() => {
            var msg = new WebMessageEvent()
            msg.setData(this.sendFromEts)
            this.ports[0].postMessageEvent(msg)
          })
        Web({ src: $rawfile("index.html"), controller: this.controller })
          .javaScriptAccess(true)
          .fileAccess(true)
4727 4728 4729
      }
    }
  }
E
ester.zhou 已提交
4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745

  // index.html
  <!DOCTYPE html>
  <html>
      <body>
          <h1>Web Message Port Demo</h1>
          <div style="font-size: 24pt;">
            <input type="button" value="5.SendToEts" onclick="PostMsgToEts(msgFromJS.value);" /><br/>
            <input id="msgFromJS" type="text" value="send this message from HTML to ets" style="font-size: 16pt;" /><br/>
          </div>
          <p class="output">display received message send from ets</p>
      </body>
      <script src="index.js"></script>
  </html>

  // index.js
E
ester.zhou 已提交
4746
  var h5Port;
E
ester.zhou 已提交
4747 4748 4749
  var output = document.querySelector('.output');
  window.addEventListener('message', function(event) {
    if (event.data == '__init_port__') {
E
ester.zhou 已提交
4750
      if(event.ports[0] != null) {
E
ester.zhou 已提交
4751
        h5Port = event.ports[0]; // 1. Save the port number sent from the eTS side.
E
ester.zhou 已提交
4752
        h5Port.onmessage = function(event) {
E
ester.zhou 已提交
4753 4754 4755
          // 2. Receive the message sent from the eTS side.
          var msg = 'Got message from ets:' + event.data;
          output.innerHTML = msg;
E
ester.zhou 已提交
4756 4757 4758 4759
        }
      }
    }
  })
E
ester.zhou 已提交
4760 4761 4762 4763 4764

  // 3. Use h5Port to send messages to the eTS side.
  function PostMsgToEts(data) {
    h5Port.postMessage(data)
  }
4765
  ```
E
ester.zhou 已提交
4766

E
ester.zhou 已提交
4767 4768 4769 4770
### getUrl<sup>9+</sup>

getUrl(): string

E
ester.zhou 已提交
4771
Obtains the URL of this page.
E
ester.zhou 已提交
4772 4773 4774

**Return value**

E
ester.zhou 已提交
4775 4776
| Type    | Description         |
| ------ | ----------- |
E
ester.zhou 已提交
4777 4778 4779 4780 4781 4782 4783 4784 4785
| string | URL of the current page.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4786
    controller: WebController = new WebController()
E
ester.zhou 已提交
4787 4788 4789 4790
    build() {
      Column() {
        Button('getUrl')
          .onClick(() => {
E
ester.zhou 已提交
4791
            console.log("url: " + this.controller.getUrl())
E
ester.zhou 已提交
4792 4793 4794 4795 4796 4797 4798
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905
### searchAllAsync<sup>9+</sup>

searchAllAsync(searchString: string): void

Searches the web page for content that matches the keyword specified by **'searchString'** and highlights the matches on the page. This API returns the result asynchronously through [onSearchResultReceive](#onsearchresultreceive9).

**Parameters**

| Name         | Type  | Mandatory  | Default Value | Description   |
| ------------ | ------ | ---- | ---- | ------- |
| searchString | string | Yes   | -    | Search keyword.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()
    @State searchString: string = "xxx"

    build() {
      Column() {
        Button('searchString')
          .onClick(() => {
            this.controller.searchAllAsync(this.searchString)
          })
        Button('clearMatches')
          .onClick(() => {
            this.controller.clearMatches()
          })
        Button('searchNext')
          .onClick(() => {
            this.controller.searchNext(true)
          })
        Web({ src: 'www.example.com', controller: this.controller })
     	  .onSearchResultReceive(ret => {
            console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
              "[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
          })
      }
    }
  }
  ```

### clearMatches<sup>9+</sup>

clearMatches(): void

Clears the matches found through [searchAllAsync](#searchallasync9).

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()

    build() {
      Column() {
        Button('clearMatches')
          .onClick(() => {
            this.controller.clearMatches()
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### searchNext<sup>9+</sup>

searchNext(forward: boolean): void

Searches for and highlights the next match.

**Parameters**

| Name    | Type   | Mandatory  | Default Value | Description       |
| ------- | ------- | ---- | ---- | ----------- |
| forward | boolean | Yes   | -    | Whether to search forward.|


**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController()

    build() {
      Column() {
        Button('searchNext')
          .onClick(() => {
            this.controller.searchNext(true)
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4906
## HitTestValue<sup>9+</sup>
E
esterzhou 已提交
4907
Implements the **HitTestValue** object. For the sample code, see [getHitTestValue](#gethittestvalue9).
E
ester.zhou 已提交
4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960

### getType<sup>9+</sup>
getType(): HitTestType

Obtains the element type of the area being clicked.

**Return value**

| Type                             | Description           |
| ------------------------------- | ------------- |
| [HitTestType](#hittesttype)| Element type of the area being clicked.|

### getExtra<sup>9+</sup>
getExtra(): string

Obtains the extra information of the area being clicked. If the area being clicked is an image or a link, the extra information is the URL of the image or link.

**Return value**

| Type    | Description          |
| ------ | ------------ |
| string | Extra information of the area being clicked.|


## WebCookie

Manages behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookie**. You can use the **getCookieManager** API in **controller** to obtain the **WebCookie** for subsequent cookie management.

### setCookie<sup>9+</sup>
setCookie(url: string, value: string): boolean

Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| url   | string | Yes   | -    | URL of the cookie to set.|
| value | string | Yes   | -    | Value of the cookie to set.        |

**Return value**

| Type     | Description           |
| ------- | ------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4961
    controller: WebController = new WebController()
E
ester.zhou 已提交
4962 4963 4964 4965 4966
  
    build() {
      Column() {
        Button('setCookie')
          .onClick(() => {
E
ester.zhou 已提交
4967 4968
            let result = this.controller.getCookieManager().setCookie("www.example.com", "a=b")
            console.log("result: " + result)
E
ester.zhou 已提交
4969 4970 4971 4972 4973 4974 4975 4976 4977
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
E
ester.zhou 已提交
4978

E
ester.zhou 已提交
4979
Saves the cookies in the memory to the drive. This API returns the result synchronously.
4980 4981

**Return value**
E
ester.zhou 已提交
4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993

| Type     | Description                  |
| ------- | -------------------- |
| boolean | Operation result.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4994
    controller: WebController = new WebController()
E
ester.zhou 已提交
4995 4996 4997 4998 4999
  
    build() {
      Column() {
        Button('saveCookieSync')
          .onClick(() => {
E
ester.zhou 已提交
5000 5001
            let result = this.controller.getCookieManager().saveCookieSync()
            console.log("result: " + result)
E
ester.zhou 已提交
5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getCookie<sup>9+</sup>
getCookie(url: string): string

Obtains the cookie value corresponding to the specified URL.

**Parameters**

E
ester.zhou 已提交
5016 5017 5018
| Name | Type  | Mandatory  | Default Value | Description             |
| ---- | ------ | ---- | ---- | ----------------- |
| url  | string | Yes   | -    | URL of the cookie value to obtain.|
E
ester.zhou 已提交
5019 5020 5021

**Return value**

E
ester.zhou 已提交
5022 5023
| Type    | Description               |
| ------ | ----------------- |
E
ester.zhou 已提交
5024 5025 5026 5027 5028 5029 5030 5031 5032 5033
| string | Cookie value corresponding to the specified URL.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5034
    controller: WebController = new WebController()
E
ester.zhou 已提交
5035 5036 5037 5038 5039
  
    build() {
      Column() {
        Button('getCookie')
          .onClick(() => {
E
ester.zhou 已提交
5040
            let value = web_webview.WebCookieManager.getCookie('www.example.com')
E
ester.zhou 已提交
5041
            console.log("value: " + value)
E
ester.zhou 已提交
5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### setCookie<sup>9+</sup>
setCookie(url: string, value: string): boolean

Sets a cookie value for the specified URL.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| url   | string | Yes   | -    | URL of the cookie to set.|
E
ester.zhou 已提交
5059
| value | string | Yes   | -    | Cookie value to set.    |
E
ester.zhou 已提交
5060 5061 5062

**Return value**

E
ester.zhou 已提交
5063 5064
| Type     | Description           |
| ------- | ------------- |
E
ester.zhou 已提交
5065 5066 5067 5068 5069 5070 5071 5072 5073 5074
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5075
    controller: WebController = new WebController()
E
ester.zhou 已提交
5076 5077 5078 5079 5080
  
    build() {
      Column() {
        Button('setCookie')
          .onClick(() => {
E
ester.zhou 已提交
5081 5082
            let result = web_webview.WebCookieManager.setCookie('www.example.com', 'a=b')
            console.log("result: " + result)
E
ester.zhou 已提交
5083 5084 5085 5086 5087 5088 5089 5090 5091 5092
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieAsync<sup>9+</sup>
saveCookieAsync(): Promise\<boolean>

E
ester.zhou 已提交
5093
Saves the cookies in the memory to the drive. This API uses a promise to return the value.
E
ester.zhou 已提交
5094 5095 5096

**Return value**

E
ester.zhou 已提交
5097 5098
| Type               | Description                         |
| ----------------- | --------------------------- |
E
ester.zhou 已提交
5099 5100 5101 5102 5103 5104 5105 5106 5107 5108
| Promise\<boolean> | Promise used to return the result.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5109
    controller: WebController = new WebController()
E
ester.zhou 已提交
5110 5111 5112 5113 5114 5115 5116
  
    build() {
      Column() {
        Button('saveCookieAsync')
          .onClick(() => {
            web_webview.WebCookieManager.saveCookieAsync()
              .then (function(result) {
E
ester.zhou 已提交
5117
                console.log("result: " + result)
E
ester.zhou 已提交
5118 5119
              })
              .catch(function(error) {
E
ester.zhou 已提交
5120 5121
                console.error("error: " + error)
              })
E
ester.zhou 已提交
5122 5123 5124 5125 5126 5127 5128 5129 5130 5131
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieAsync<sup>9+</sup>
saveCookieAsync(callback: AsyncCallback\<boolean>): void

E
ester.zhou 已提交
5132
Saves the cookies in the memory to the drive. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
5133 5134 5135

**Parameters**

E
ester.zhou 已提交
5136 5137 5138
| Name     | Type                   | Mandatory  | Default Value | Description                        |
| -------- | ----------------------- | ---- | ---- | ---------------------------- |
| callback | AsyncCallback\<boolean> | Yes   | -    | Callback used to return the operation result.|
E
ester.zhou 已提交
5139 5140 5141 5142 5143 5144 5145 5146 5147

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5148
    controller: WebController = new WebController()
E
ester.zhou 已提交
5149 5150 5151 5152 5153 5154
  
    build() {
      Column() {
        Button('saveCookieAsync')
          .onClick(() => {
            web_webview.WebCookieManager.saveCookieAsync(function(result) {
E
ester.zhou 已提交
5155 5156
              console.log("result: " + result)
            })
E
ester.zhou 已提交
5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### isCookieAllowed<sup>9+</sup>
isCookieAllowed(): boolean

Checks whether the **WebCookieManager** instance has the permission to send and receive cookies.

**Return value**

E
ester.zhou 已提交
5171 5172
| Type     | Description                 |
| ------- | ------------------- |
E
ester.zhou 已提交
5173 5174 5175 5176 5177 5178 5179 5180 5181 5182
| boolean | Whether the **WebCookieManager** instance has the permission to send and receive cookies.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5183
    controller: WebController = new WebController()
E
ester.zhou 已提交
5184 5185 5186 5187 5188
  
    build() {
      Column() {
        Button('isCookieAllowed')
          .onClick(() => {
E
ester.zhou 已提交
5189 5190
            let result = web_webview.WebCookieManager.isCookieAllowed()
            console.log("result: " + result)
E
ester.zhou 已提交
5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### putAcceptCookieEnabled<sup>9+</sup>
putAcceptCookieEnabled(accept: boolean): void

Sets whether the **WebCookieManager** instance has the permission to send and receive cookies.

**Parameters**

E
ester.zhou 已提交
5205 5206 5207
| Name   | Type   | Mandatory  | Default Value | Description                 |
| ------ | ------- | ---- | ---- | --------------------- |
| accept | boolean | Yes   | -    | Whether the **WebCookieManager** instance has the permission to send and receive cookies.|
E
ester.zhou 已提交
5208 5209 5210 5211 5212 5213 5214 5215 5216

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5217
    controller: WebController = new WebController()
E
ester.zhou 已提交
5218 5219 5220 5221 5222
  
    build() {
      Column() {
        Button('putAcceptCookieEnabled')
          .onClick(() => {
E
ester.zhou 已提交
5223
            web_webview.WebCookieManager.putAcceptCookieEnabled(false)
E
ester.zhou 已提交
5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### isThirdPartyCookieAllowed<sup>9+</sup>
isThirdCookieAllowed(): boolean

Checks whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.

**Return value**

E
ester.zhou 已提交
5238 5239
| Type     | Description                    |
| ------- | ---------------------- |
E
ester.zhou 已提交
5240 5241 5242 5243 5244 5245 5246 5247 5248 5249
| boolean | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5250
    controller: WebController = new WebController()
E
ester.zhou 已提交
5251 5252 5253 5254 5255
  
    build() {
      Column() {
        Button('isThirdPartyCookieAllowed')
          .onClick(() => {
E
ester.zhou 已提交
5256 5257
            let result = web_webview.WebCookieManager.isThirdPartyCookieAllowed()
            console.log("result: " + result)
E
ester.zhou 已提交
5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### putAcceptThirdPartyCookieEnabled<sup>9+</sup>
putAcceptThirdPartyCookieEnabled(accept: boolean): void

Sets whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.

**Parameters**

E
ester.zhou 已提交
5272 5273 5274
| Name   | Type   | Mandatory  | Default Value | Description                    |
| ------ | ------- | ---- | ---- | ------------------------ |
| accept | boolean | Yes   | -    | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|
E
ester.zhou 已提交
5275 5276 5277 5278 5279 5280 5281 5282 5283

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5284
    controller: WebController = new WebController()
E
ester.zhou 已提交
5285 5286 5287 5288 5289
  
    build() {
      Column() {
        Button('putAcceptThirdPartyCookieEnabled')
          .onClick(() => {
E
ester.zhou 已提交
5290
            web_webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(false)
E
ester.zhou 已提交
5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### existCookie<sup>9+</sup>
existCookie(): boolean

Checks whether cookies exist.

**Return value**

E
ester.zhou 已提交
5305 5306
| Type     | Description         |
| ------- | ----------- |
E
ester.zhou 已提交
5307 5308 5309 5310 5311 5312 5313 5314 5315 5316
| boolean | Whether cookies exist.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5317
    controller: WebController = new WebController()
E
ester.zhou 已提交
5318 5319 5320 5321 5322
  
    build() {
      Column() {
        Button('existCookie')
          .onClick(() => {
E
ester.zhou 已提交
5323 5324
            let result = web_webview.WebCookieManager.existCookie()
            console.log("result: " + result)
E
ester.zhou 已提交
5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteEntireCookie<sup>9+</sup>
deleteEntireCookie(): void

Deletes all cookies.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5345
    controller: WebController = new WebController()
E
ester.zhou 已提交
5346 5347 5348 5349 5350
  
    build() {
      Column() {
        Button('deleteEntireCookie')
          .onClick(() => {
E
ester.zhou 已提交
5351
            web_webview.WebCookieManager.deleteEntireCookie()
E
ester.zhou 已提交
5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteSessionCookie<sup>9+</sup>
deleteSessionCookie(): void

Deletes all session cookies.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5372
    controller: WebController = new WebController()
E
ester.zhou 已提交
5373 5374 5375 5376 5377
  
    build() {
      Column() {
        Button('deleteSessionCookie')
          .onClick(() => {
E
ester.zhou 已提交
5378
            web_webview.WebCookieManager.deleteSessionCookie()
E
ester.zhou 已提交
5379 5380 5381 5382 5383 5384 5385
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
5386
## MessageLevel
E
ester.zhou 已提交
5387

E
ester.zhou 已提交
5388 5389 5390 5391 5392 5393 5394
| Name   | Description   |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info  | Information level.|
| Log   | Log level.|
| Warn  | Warning level. |
E
ester.zhou 已提交
5395

E
ester.zhou 已提交
5396
## RenderExitReason
E
ester.zhou 已提交
5397

E
ester.zhou 已提交
5398
Enumerates the reasons why the rendering process exits.
E
ester.zhou 已提交
5399

E
ester.zhou 已提交
5400 5401 5402 5403 5404 5405 5406
| Name                        | Description               |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally.        |
| ProcessWasKilled           | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed             | The rendering process crashes due to segmentation or other errors.   |
| ProcessOom                 | The program memory is running low.          |
| ProcessExitUnknown         | Other reason.            |
E
ester.zhou 已提交
5407

E
ester.zhou 已提交
5408
## MixedMode
E
ester.zhou 已提交
5409

E
ester.zhou 已提交
5410 5411 5412 5413 5414
| Name        | Description                                |
| ---------- | ---------------------------------- |
| All        | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded.|
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded.          |
| None       | HTTP and HTTPS hybrid content cannot be loaded.              |
E
ester.zhou 已提交
5415

E
ester.zhou 已提交
5416 5417 5418 5419 5420 5421 5422
## CacheMode
| Name     | Description                                  |
| ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None    | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.    |
| Online  | The cache is not used to load the resources. All resources are obtained from the Internet.              |
| Only    | The cache alone is used to load the resources.                       |
E
ester.zhou 已提交
5423

E
ester.zhou 已提交
5424 5425 5426 5427 5428 5429 5430
## FileSelectorMode
| Name                  | Description        |
| -------------------- | ---------- |
| FileOpenMode         | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. |
| FileOpenFolderMode   | Open and upload a folder.|
| FileSaveMode         | Save a file.   |
E
ester.zhou 已提交
5431

E
ester.zhou 已提交
5432
 ## HitTestType
E
ester.zhou 已提交
5433

E
ester.zhou 已提交
5434 5435 5436 5437 5438 5439 5440 5441 5442 5443
| Name           | Description                      |
| ------------- | ------------------------ |
| EditText      | Editable area.                 |
| Email         | Email address.                 |
| HttpAnchor    | Hyperlink whose **src** is **http**.          |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img           | HTML::img tag.            |
| Map           | Geographical address.                   |
| Phone         | Phone number.                   |
| Unknown       | Unknown content.                   |
E
ester.zhou 已提交
5444

E
ester.zhou 已提交
5445
## SslError<sup>9+</sup>
E
ester.zhou 已提交
5446

E
ester.zhou 已提交
5447
Enumerates the error codes returned by **onSslErrorEventReceive** API.
E
ester.zhou 已提交
5448

E
ester.zhou 已提交
5449 5450 5451 5452 5453 5454
| Name          | Description         |
| ------------ | ----------- |
| Invalid      | Minor error.      |
| HostMismatch | The host name does not match.    |
| DateInvalid  | The certificate has an invalid date.    |
| Untrusted    | The certificate issuer is not trusted.|
5455

E
ester.zhou 已提交
5456
## ProtectedResourceType<sup>9+</sup>
5457

E
ester.zhou 已提交
5458 5459 5460
| Name       | Description           | Remarks                        |
| --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|
5461

E
ester.zhou 已提交
5462
## WebDarkMode<sup>9+</sup>
5463 5464
| Name     | Description                                  |
| ------- | ------------------------------------ |
E
ester.zhou 已提交
5465 5466 5467
| Off     | The web dark mode is disabled.                    |
| On      | The web dark mode is enabled.                    |
| Auto    | The web dark mode setting follows the system settings.                |
E
ester.zhou 已提交
5468 5469 5470

## WebMessagePort<sup>9+</sup>

E
ester.zhou 已提交
5471
Implements a **WebMessagePort** instance, which can be used to send and receive messages.
E
ester.zhou 已提交
5472 5473 5474 5475 5476 5477 5478 5479 5480

### close<sup>9+</sup>
close(): void

Disables this message port.

### postMessageEvent<sup>9+</sup>
postMessageEvent(message: WebMessageEvent): void

E
ester.zhou 已提交
5481
Sends messages. For the complete sample code, see [postMessage](#postmessage9).
E
ester.zhou 已提交
5482 5483 5484

**Parameters**

E
ester.zhou 已提交
5485 5486 5487
| Name    | Type                                | Mandatory  | Default Value | Description   |
| ------- | ------------------------------------ | ---- | ---- | ------- |
| message | [WebMessageEvent](#webmessageevent9) | Yes   | -    | Message to send.|
E
ester.zhou 已提交
5488 5489 5490 5491 5492 5493 5494 5495

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5496 5497
    controller: WebController = new WebController()
    ports: WebMessagePort[] = null
E
ester.zhou 已提交
5498 5499 5500 5501 5502

    build() {
      Column() {
        Button('postMessageEvent')
          .onClick(() => {
E
ester.zhou 已提交
5503 5504 5505
            var msg = new WebMessageEvent()
            msg.setData("post message from ets to html5")
            this.ports[0].postMessageEvent(msg)
E
ester.zhou 已提交
5506 5507 5508 5509 5510 5511 5512 5513 5514 5515
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### onMessageEvent<sup>9+</sup>
onMessageEvent(callback: (result: string) => void): void

E
ester.zhou 已提交
5516
Registers a callback to receive messages from an HTML5 page. For the complete sample code, see [postMessage](#postmessage9).
E
ester.zhou 已提交
5517 5518 5519

**Parameters**

E
ester.zhou 已提交
5520 5521 5522
| Name     | Type    | Mandatory  | Default Value | Description      |
| -------- | -------- | ---- | ---- | ---------- |
| callback | function | Yes   | -    | Callback for receiving messages.|
E
ester.zhou 已提交
5523 5524 5525 5526 5527 5528 5529 5530

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5531 5532
    controller: WebController = new WebController()
    ports: WebMessagePort[] = null
E
ester.zhou 已提交
5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559

    build() {
      Column() {
        Button('onMessageEvent')
          .onClick(() => {
            this.ports[0].onMessageEvent((result: string) => {
              console.log("received message from html5, on message:" + result);
            })
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```


## WebMessageEvent<sup>9+</sup>

Implements the **WebMessageEvent** object to encapsulate the message and port.

### getData<sup>9+</sup>
getData(): string

Obtains the messages stored in this object.

**Return value**

E
ester.zhou 已提交
5560 5561
| Type    | Description            |
| ------ | -------------- |
E
ester.zhou 已提交
5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575
| string | Message stored in the object of this type.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    build() {
      Column() {
        Button('getPorts')
          .onClick(() => {
            var msgEvent = new WebMessageEvent();
E
ester.zhou 已提交
5576 5577 5578
            msgEvent.setData("message event data")
            var messageData = msgEvent.getData()
            console.log("message is:" + messageData)
E
ester.zhou 已提交
5579 5580 5581 5582 5583 5584 5585 5586 5587
          })
      }
    }
  }
  ```

### setData<sup>9+</sup>
setData(data: string): void

E
ester.zhou 已提交
5588
Sets the message in this object. For the complete sample code, see [postMessage](#postmessage9).
E
ester.zhou 已提交
5589 5590 5591

**Parameters**

E
ester.zhou 已提交
5592 5593 5594
| Name | Type  | Mandatory  | Default Value | Description   |
| ---- | ------ | ---- | ---- | ------- |
| data | string | Yes   | -    | Message to send.|
E
ester.zhou 已提交
5595 5596 5597 5598 5599 5600 5601 5602

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5603 5604
    controller: WebController = new WebController()
    ports: WebMessagePort[] = null
E
ester.zhou 已提交
5605 5606 5607 5608 5609

    build() {
      Column() {
        Button('setData')
          .onClick(() => {
E
ester.zhou 已提交
5610 5611 5612
            var msg = new WebMessageEvent()
            msg.setData("post message from ets to HTML5")
            this.ports[0].postMessageEvent(msg)
E
ester.zhou 已提交
5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
### getPorts<sup>9+</sup>
getPorts(): Array\<WebMessagePort\>

Obtains the message port stored in this object.

**Return value**

E
ester.zhou 已提交
5626 5627
| Type                                      | Description              |
| ---------------------------------------- | ---------------- |
E
ester.zhou 已提交
5628 5629 5630 5631 5632 5633 5634 5635 5636
| Array\<[WebMessagePort](#webmessageport9)\> | Message port stored in the object of this type.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5637
    ports: WebMessagePort[] = null
E
ester.zhou 已提交
5638 5639 5640 5641
    build() {
      Column() {
        Button('getPorts')
          .onClick(() => {
E
ester.zhou 已提交
5642 5643 5644 5645 5646
            var sendPortArray = new Array(this.ports[0])
            var msgEvent = new WebMessageEvent()
            msgEvent.setPorts(sendPortArray)
            var getPorts = msgEvent.getPorts()
            console.log("Ports is:" + getPorts)
E
ester.zhou 已提交
5647 5648 5649 5650 5651 5652 5653 5654 5655
          })
      }
    }
  }
  ```

### setPorts<sup>9+</sup>
setPorts(ports: Array\<WebMessagePort\>): void

E
ester.zhou 已提交
5656
Sets the message port in this object. For the complete sample code, see [postMessage](#postmessage9).
E
ester.zhou 已提交
5657 5658 5659

**Parameters**

E
ester.zhou 已提交
5660 5661 5662
| Name  | Type                                    | Mandatory  | Default Value | Description     |
| ----- | ---------------------------------------- | ---- | ---- | --------- |
| ports | Array\<[WebMessagePort](#webmessageport9)\> | Yes   | -    | Message port.|
E
ester.zhou 已提交
5663 5664 5665 5666 5667 5668 5669 5670

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
5671 5672
    controller: WebController = new WebController()
    ports: WebMessagePort[] = null
E
ester.zhou 已提交
5673 5674 5675 5676 5677
  
    build() {
      Column() {
        Button('setPorts')
          .onClick(() => {
E
ester.zhou 已提交
5678 5679 5680 5681 5682
            var sendPortArray = new Array(this.ports[1])
            var msgEvent = new WebMessageEvent()
            msgEvent.setData("__init_ports__")
            msgEvent.setPorts(sendPortArray)
            this.controller.postMessage({message: msgEvent, uri: "*"})
E
ester.zhou 已提交
5683 5684 5685 5686 5687 5688
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
esterzhou 已提交
5689 5690 5691

## DataResubmissionHandler<sup>9+</sup>

E
ester.zhou 已提交
5692
Implements the **DataResubmissionHandler** object for resubmitting or canceling the web form data.
E
esterzhou 已提交
5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746

### resend<sup>9+</sup>

resend(): void

Resends the web form data.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
         .onDataResubmitted((event) => {
          console.log('onDataResubmitted')
          event.handler.resend();
        })
      }
    }
  }
  ```

###  cancel<sup>9+</sup>

cancel(): void

Cancels the resending of web form data.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
         .onDataResubmitted((event) => {
          console.log('onDataResubmitted')
          event.handler.cancel();
        })
      }
    }
  }
  ```