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

E
ester.zhou 已提交
3
The **<Web\>** component can be used to display web pages. It can be used with the [@ohos.web.webview](../apis/js-apis-webview.md) module, which provides APIs for web control.
E
ester.zhou 已提交
4

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: WebviewController | WebController})
E
ester.zhou 已提交
20 21 22 23

> **NOTE**
>
> Transition animation is not supported.
E
ester.zhou 已提交
24 25
>
> **\<Web>** components on a page must be bound to different **WebviewController**s.
26 27

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

E
ester.zhou 已提交
29 30
| Name       | Type                                    | Mandatory  | Description   |
| ---------- | ---------------------------------------- | ---- | ------- |
E
ester.zhou 已提交
31
| src        | [ResourceStr](ts-types.md)               | Yes   | Address of a web page resource. To access local resource files, use the **$rawfile** or **resource** protocol. To load a local resource file in the sandbox outside of the application package, use **file://** to specify the path of the sandbox.|
E
ester.zhou 已提交
32
| controller | [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes   | Controller. **WebController** is deprecated since API version 9. You are advised to use **WebviewController** instead.|
33 34

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

E
ester.zhou 已提交
36
  Example of loading online web pages:
37 38
  ```ts
  // xxx.ets
E
ester.zhou 已提交
39 40
  import web_webview from '@ohos.web.webview'

41 42 43
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
44
    controller: web_webview.WebviewController = new web_webview.WebviewController()
45 46
    build() {
      Column() {
E
ester.zhou 已提交
47
        Web({ src: 'www.example.com', controller: this.controller })
48 49 50 51
      }
    }
  }
  ```
E
ester.zhou 已提交
52 53

  Example of loading local web pages:
E
ester.zhou 已提交
54 55 56
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
E
ester.zhou 已提交
57

E
ester.zhou 已提交
58 59 60 61 62 63
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    build() {
      Column() {
E
ester.zhou 已提交
64 65
        // Load a local resource file through $rawfile.
        Web({ src: $rawfile("index.html"), controller: this.controller })
E
ester.zhou 已提交
66 67 68 69 70
      }
    }
  }
  ```

E
ester.zhou 已提交
71 72
  ```ts
  // xxx.ets
E
ester.zhou 已提交
73 74
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
75 76 77
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
78
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
79 80
    build() {
      Column() {
E
ester.zhou 已提交
81 82
        // Load a local resource file through the resource protocol.
        Web({ src: "resource://rawfile/index.html", controller: this.controller })
E
ester.zhou 已提交
83 84 85 86 87
      }
    }
  }
  ```

E
ester.zhou 已提交
88 89
  Example of loading local resource files in the sandbox:

E
ester.zhou 已提交
90
  1. Use [globalthis](../../application-models/uiability-data-sync-with-ui.md#using-globalthis-between-uiability-and-page) to obtain the path of the sandbox.
E
ester.zhou 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
     ```ts
     // xxx.ets
     import web_webview from '@ohos.web.webview'
     let url = 'file://' + globalThis.filesDir + '/xxx.html'

     @Entry
     @Component
     struct WebComponent {
       controller: web_webview.WebviewController = new web_webview.WebviewController()
       build() {
         Column() {
           // Load the files in the sandbox.
           Web({ src: url, controller: this.controller })
         }
       }
     }
     ```

  2. Modify the **MainAbility.ts** file.
  
     The following uses **filesDir** as an example to describe how to obtain the path of the sandbox. For details about how to obtain other paths, see [Obtaining the Application Development Path](../../application-models/application-context-stage.md#obtaining-the-application-development-path).
     ```ts
     // xxx.ts
     import UIAbility from '@ohos.app.ability.UIAbility';
     import web_webview from '@ohos.web.webview';

     export default class EntryAbility extends UIAbility {
         onCreate(want, launchParam) {
             // Bind filesDir to the globalThis object to implement data synchronization between the UIAbility component and the UI.
             globalThis.filesDir = this.context.filesDir
             console.log("Sandbox path is " + globalThis.filesDir)
         }
     }
     ```

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

## Attributes
137

E
ester.zhou 已提交
138
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).
139 140 141 142 143 144 145 146

### domStorageAccess

domStorageAccess(domStorageAccess: boolean)

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

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

E
ester.zhou 已提交
148 149
| Name             | Type   | Mandatory  | Default Value  | Description                                |
| ---------------- | ------- | ---- | ----- | ------------------------------------ |
150 151 152
| domStorageAccess | boolean | Yes   | false | Whether to enable the DOM Storage API.|

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

154 155
  ```ts
  // xxx.ets
E
ester.zhou 已提交
156 157
  import web_webview from '@ohos.web.webview'

158 159 160
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
161
    controller: web_webview.WebviewController = new web_webview.WebviewController()
162 163
    build() {
      Column() {
E
ester.zhou 已提交
164 165
        Web({ src: 'www.example.com', controller: this.controller })
          .domStorageAccess(true)
166 167 168 169 170 171 172 173 174
      }
    }
  }
  ```

### fileAccess

fileAccess(fileAccess: boolean)

E
ester.zhou 已提交
175
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).
176 177

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

E
ester.zhou 已提交
179 180
| Name       | Type   | Mandatory  | Default Value | Description                  |
| ---------- | ------- | ---- | ---- | ---------------------- |
E
ester.zhou 已提交
181
| fileAccess | boolean | Yes   | true | Whether to enable access to the file system in the application. By default, this feature is enabled.|
182 183

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

185 186
  ```ts
  // xxx.ets
E
ester.zhou 已提交
187 188
  import web_webview from '@ohos.web.webview'

189 190 191
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
192
    controller: web_webview.WebviewController = new web_webview.WebviewController()
193 194
    build() {
      Column() {
E
ester.zhou 已提交
195 196
        Web({ src: 'www.example.com', controller: this.controller })
          .fileAccess(true)
197 198 199 200 201 202 203 204 205 206 207 208
      }
    }
  }
  ```

### imageAccess

imageAccess(imageAccess: boolean)

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

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

210 211
| Name        | Type   | Mandatory  | Default Value | Description           |
| ----------- | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
212
| imageAccess | boolean | Yes   | true | Whether to enable automatic image loading.|
213 214 215 216

**Example**
  ```ts
  // xxx.ets
E
ester.zhou 已提交
217 218
  import web_webview from '@ohos.web.webview'

219 220 221
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
222
    controller: web_webview.WebviewController = new web_webview.WebviewController()
223 224
    build() {
      Column() {
E
ester.zhou 已提交
225 226
        Web({ src: 'www.example.com', controller: this.controller })
          .imageAccess(true)
227 228 229 230 231 232 233 234
      }
    }
  }
  ```

### javaScriptProxy

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

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

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

E
ester.zhou 已提交
241 242 243 244 245
| 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. |
E
ester.zhou 已提交
246
| controller | [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes   | -    | Controller. **WebController** is deprecated since API version 9. You are advised to use **WebviewController** instead.|
247 248

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

E
ester.zhou 已提交
250 251 252 253 254 255 256 257
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'

  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
258 259
    testObj = {
      test: (data1, data2, data3) => {
E
ester.zhou 已提交
260 261 262 263
        console.log("data1:" + data1)
        console.log("data2:" + data2)
        console.log("data3:" + data3)
        return "AceString"
264 265
      },
      toString: () => {
E
ester.zhou 已提交
266
        console.log('toString' + "interface instead.")
267 268 269 270
      }
    }
    build() {
      Column() {
E
ester.zhou 已提交
271 272 273 274 275 276 277
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          .javaScriptProxy({
            object: this.testObj,
            name: "objName",
            methodList: ["test", "toString"],
            controller: this.controller,
278 279 280 281 282 283 284 285 286 287 288 289 290
        })
      }
    }
  }
  ```

### javaScriptAccess

javaScriptAccess(javaScriptAccess: boolean)

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

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

292 293 294 295 296
| Name             | Type   | Mandatory  | Default Value | Description               |
| ---------------- | ------- | ---- | ---- | ------------------- |
| javaScriptAccess | boolean | Yes   | true | Whether JavaScript scripts can be executed.|

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

298 299
  ```ts
  // xxx.ets
E
ester.zhou 已提交
300 301
  import web_webview from '@ohos.web.webview'

302 303 304
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
305
    controller: web_webview.WebviewController = new web_webview.WebviewController()
306 307
    build() {
      Column() {
E
ester.zhou 已提交
308 309
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
310 311 312 313 314 315 316 317 318 319 320 321
      }
    }
  }
  ```

### 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 已提交
322

E
ester.zhou 已提交
323 324
| Name      | Type                       | Mandatory  | Default Value           | Description     |
| --------- | --------------------------- | ---- | -------------- | --------- |
E
ester.zhou 已提交
325
| mixedMode | [MixedMode](#mixedmode)| Yes   | MixedMode.None | Mixed content to load.|
326 327

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

329 330
  ```ts
  // xxx.ets
E
ester.zhou 已提交
331 332
  import web_webview from '@ohos.web.webview'

333 334 335
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
336
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
337
    @State mode: MixedMode = MixedMode.All
338 339
    build() {
      Column() {
E
ester.zhou 已提交
340 341
        Web({ src: 'www.example.com', controller: this.controller })
          .mixedMode(this.mode)
342 343 344 345 346 347 348 349 350 351 352 353
      }
    }
  }
  ```

### 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 已提交
354

355 356 357 358 359
| 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 已提交
360

361 362
  ```ts
  // xxx.ets
E
ester.zhou 已提交
363 364
  import web_webview from '@ohos.web.webview'

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

### zoomAccess

zoomAccess(zoomAccess: boolean)

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

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

386 387 388 389 390
| Name       | Type   | Mandatory  | Default Value | Description         |
| ---------- | ------- | ---- | ---- | ------------- |
| zoomAccess | boolean | Yes   | true | Whether to enable zoom gestures.|

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

392 393
  ```ts
  // xxx.ets
E
ester.zhou 已提交
394 395
  import web_webview from '@ohos.web.webview'

396 397 398
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
399
    controller: web_webview.WebviewController = new web_webview.WebviewController()
400 401
    build() {
      Column() {
E
ester.zhou 已提交
402 403
        Web({ src: 'www.example.com', controller: this.controller })
          .zoomAccess(true)
404 405 406 407 408 409 410 411 412 413 414 415
      }
    }
  }
  ```

### 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 已提交
416

417 418
| Name               | Type   | Mandatory  | Default Value | Description           |
| ------------------ | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
419
| overviewModeAccess | boolean | Yes   | true | Whether to load web pages by using the overview mode.|
420 421

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

423 424
  ```ts
  // xxx.ets
E
ester.zhou 已提交
425 426
  import web_webview from '@ohos.web.webview'

427 428 429
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
430
    controller: web_webview.WebviewController = new web_webview.WebviewController()
431 432
    build() {
      Column() {
E
ester.zhou 已提交
433 434
        Web({ src: 'www.example.com', controller: this.controller })
          .overviewModeAccess(true)
435 436 437 438 439 440 441 442 443 444 445 446
      }
    }
  }
  ```

### databaseAccess

databaseAccess(databaseAccess: boolean)

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

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

E
ester.zhou 已提交
448 449
| Name           | Type   | Mandatory  | Default Value  | Description             |
| -------------- | ------- | ---- | ----- | ----------------- |
E
ester.zhou 已提交
450
| databaseAccess | boolean | Yes   | false | Whether to enable database access.|
451 452

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

454 455
  ```ts
  // xxx.ets
E
ester.zhou 已提交
456 457
  import web_webview from '@ohos.web.webview'

458 459 460
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
461
    controller: web_webview.WebviewController = new web_webview.WebviewController()
462 463
    build() {
      Column() {
E
ester.zhou 已提交
464 465
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
466 467 468 469 470 471 472 473 474 475 476 477
      }
    }
  }
  ```

### geolocationAccess

geolocationAccess(geolocationAccess: boolean)

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

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

E
ester.zhou 已提交
479 480 481
| Name              | Type   | Mandatory  | Default Value | Description           |
| ----------------- | ------- | ---- | ---- | --------------- |
| geolocationAccess | boolean | Yes   | true | Whether to enable geolocation access.|
482 483

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

485 486
  ```ts
  // xxx.ets
E
ester.zhou 已提交
487 488
  import web_webview from '@ohos.web.webview'

489 490 491
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
492
    controller: web_webview.WebviewController = new web_webview.WebviewController()
493 494
    build() {
      Column() {
E
ester.zhou 已提交
495 496 497 498 499 500 501 502 503 504 505
        Web({ src: 'www.example.com', controller: this.controller })
          .geolocationAccess(true)
      }
    }
  }
  ```

### mediaPlayGestureAccess

mediaPlayGestureAccess(access: boolean)

E
ester.zhou 已提交
506
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 已提交
507 508 509

**Parameters**

E
ester.zhou 已提交
510 511
| Name   | Type   | Mandatory  | Default Value | Description             |
| ------ | ------- | ---- | ---- | ----------------- |
E
ester.zhou 已提交
512
| access | boolean | Yes   | true | Whether video playback must be started by user gestures.|
E
ester.zhou 已提交
513 514 515 516 517

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
518 519
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
520 521 522
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
523
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
524
    @State access: boolean = true
E
ester.zhou 已提交
525 526 527 528
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .mediaPlayGestureAccess(this.access)
529 530 531 532 533
      }
    }
  }
  ```

E
ester.zhou 已提交
534 535 536 537 538 539
### multiWindowAccess<sup>9+</sup>

multiWindowAccess(multiWindow: boolean)

Sets whether to enable the multi-window permission.

E
ester.zhou 已提交
540 541
Enabling the multi-window permission requires implementation of the **onWindowNew** event. For details about the sample code, see [onWindowNew](#onwindownew9).

E
ester.zhou 已提交
542 543
**Parameters**

E
ester.zhou 已提交
544 545
| Name        | Type   | Mandatory  | Default Value  | Description        |
| ----------- | ------- | ---- | ----- | ------------ |
E
ester.zhou 已提交
546 547 548 549 550 551
| multiWindow | boolean | Yes   | false | Whether to enable the multi-window permission.|

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
552 553
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
554 555 556
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
557
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
558 559 560
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
561
        .multiWindowAccess(false)
E
ester.zhou 已提交
562 563 564 565 566
      }
    }
  }
  ```

E
ester.zhou 已提交
567 568 569 570
### horizontalScrollBarAccess<sup>9+</sup>

horizontalScrollBarAccess(horizontalScrollBar: boolean)

E
ester.zhou 已提交
571
Sets whether to display the horizontal scrollbar, including the default system scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed.
E
ester.zhou 已提交
572 573 574 575 576 577 578 579 580 581 582

**Parameters**

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

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
583 584
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
585 586 587
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
588
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
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
    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)

E
ester.zhou 已提交
624
Sets whether to display the vertical scrollbar, including the default system scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed.
E
ester.zhou 已提交
625 626 627 628 629 630 631 632 633 634 635

**Parameters**

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

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
636 637
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
638 639 640
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
641
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
    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>
  ```


674 675 676 677 678 679 680
### cacheMode

cacheMode(cacheMode: CacheMode)

Sets the cache mode.

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

E
ester.zhou 已提交
682 683
| Name      | Type                       | Mandatory  | Default Value              | Description     |
| --------- | --------------------------- | ---- | ----------------- | --------- |
684 685 686
| cacheMode | [CacheMode](#cachemode)| Yes   | CacheMode.Default | Cache mode to set.|

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

688 689
  ```ts
  // xxx.ets
E
ester.zhou 已提交
690 691
  import web_webview from '@ohos.web.webview'

692 693 694
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
695
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
696
    @State mode: CacheMode = CacheMode.None
697 698
    build() {
      Column() {
E
ester.zhou 已提交
699 700
        Web({ src: 'www.example.com', controller: this.controller })
          .cacheMode(this.mode)
701 702 703 704 705
      }
    }
  }
  ```

E
ester.zhou 已提交
706
### textZoomRatio<sup>9+</sup>
707 708 709 710 711 712

textZoomRatio(textZoomRatio: number)

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

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

E
ester.zhou 已提交
714 715 716
| Name          | Type  | Mandatory  | Default Value | Description           |
| ------------- | ------ | ---- | ---- | --------------- |
| textZoomRatio | number | Yes   | 100  | Text zoom ratio to set.|
717 718

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

720 721
  ```ts
  // xxx.ets
E
ester.zhou 已提交
722 723
  import web_webview from '@ohos.web.webview'

724 725 726
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
727
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
728
    @State atio: number = 150
729 730
    build() {
      Column() {
E
ester.zhou 已提交
731 732
        Web({ src: 'www.example.com', controller: this.controller })
          .textZoomRatio(this.atio)
733 734 735 736 737
      }
    }
  }
  ```

E
ester.zhou 已提交
738 739 740 741 742 743 744 745
### initialScale<sup>9+</sup>

initialScale(percent: number)

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

**Parameters**

E
ester.zhou 已提交
746 747 748
| Name    | Type  | Mandatory  | Default Value | Description           |
| ------- | ------ | ---- | ---- | --------------- |
| percent | number | Yes   | 100  | Scale factor of the entire page.|
E
ester.zhou 已提交
749 750 751 752 753

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
754 755
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
756 757 758
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
759
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
760 761 762 763 764 765 766 767 768 769
    @State percent: number = 100
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .initialScale(this.percent)
      }
    }
  }
  ```

770 771 772 773 774 775 776
### userAgent

userAgent(userAgent: string)

Sets the user agent.

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

778 779 780 781 782
| Name      | Type  | Mandatory  | Default Value | Description     |
| --------- | ------ | ---- | ---- | --------- |
| userAgent | string | Yes   | -    | User agent to set.|

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

784 785
  ```ts
  // xxx.ets
E
ester.zhou 已提交
786 787
  import web_webview from '@ohos.web.webview'

788 789 790
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
791
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
792
    @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'
793 794
    build() {
      Column() {
E
ester.zhou 已提交
795 796
        Web({ src: 'www.example.com', controller: this.controller })
          .userAgent(this.userAgent)
797 798 799 800
      }
    }
  }
  ```
E
ester.zhou 已提交
801

E
esterzhou 已提交
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
### 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 已提交
837
Sets the default fixed font size for the web page.
E
esterzhou 已提交
838 839 840 841 842

**Parameters**

| Name| Type| Mandatory| Default Value| Description                    |
| ------ | -------- | ---- | ------ | ---------------------------- |
E
ester.zhou 已提交
843
| 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 已提交
844 845 846 847 848 849 850 851 852 853

**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 已提交
854
    @State fontSize: number = 16
E
esterzhou 已提交
855 856 857
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
858
          .defaultFixedFontSize(this.fontSize)
E
esterzhou 已提交
859 860 861 862 863 864 865 866 867
      }
    }
  }
  ```

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

defaultFontSize(size: number)

E
ester.zhou 已提交
868
Sets the default font size for the web page.
E
esterzhou 已提交
869 870 871 872 873

**Parameters**

| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
E
ester.zhou 已提交
874
| 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 已提交
875 876 877 878 879 880 881 882 883 884

**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 已提交
885
    @State fontSize: number = 13
E
esterzhou 已提交
886 887 888
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
889
          .defaultFontSize(this.fontSize)
E
esterzhou 已提交
890 891 892 893 894 895 896 897 898
      }
    }
  }
  ```

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

minFontSize(size: number)

E
ester.zhou 已提交
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
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 已提交
931 932 933 934 935

**Parameters**

| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
E
ester.zhou 已提交
936
| 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 已提交
937 938 939 940 941 942 943 944 945 946

**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 已提交
947
    @State fontSize: number = 13
E
esterzhou 已提交
948 949 950
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
951
          .minLogicalFontSize(this.fontSize)
E
esterzhou 已提交
952 953 954 955 956
      }
    }
  }
  ```

E
ester.zhou 已提交
957

E
esterzhou 已提交
958 959 960 961
### webFixedFont<sup>9+</sup>

webFixedFont(family: string)

E
ester.zhou 已提交
962
Sets the fixed font family for the web page.
E
esterzhou 已提交
963 964 965 966 967

**Parameters**

| Name| Type| Mandatory| Default Value   | Description                    |
| ------ | -------- | ---- | --------- | ---------------------------- |
E
ester.zhou 已提交
968
| family | string   | Yes  | monospace | Fixed font family to set.|
E
esterzhou 已提交
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992

**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 已提交
993
Sets the sans serif font family for the web page.
E
esterzhou 已提交
994 995 996 997 998

**Parameters**

| Name| Type| Mandatory| Default Value    | Description                         |
| ------ | -------- | ---- | ---------- | --------------------------------- |
E
ester.zhou 已提交
999
| family | string   | Yes  | sans-serif | Sans serif font family to set.|
E
esterzhou 已提交
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023

**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 已提交
1024
Sets the serif font family for the web page.
E
esterzhou 已提交
1025 1026 1027 1028 1029

**Parameters**

| Name| Type| Mandatory| Default Value| Description                    |
| ------ | -------- | ---- | ------ | ---------------------------- |
E
ester.zhou 已提交
1030
| family | string   | Yes  | serif  | Serif font family to set.|
E
esterzhou 已提交
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054

**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 已提交
1055
Sets the standard font family for the web page.
E
esterzhou 已提交
1056 1057 1058 1059 1060

**Parameters**

| Name| Type| Mandatory| Default Value    | Description                       |
| ------ | -------- | ---- | ---------- | ------------------------------- |
E
ester.zhou 已提交
1061
| family | string   | Yes  | sans serif | Standard font family to set.|
E
esterzhou 已提交
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085

**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 已提交
1086
Sets the fantasy font family for the web page.
E
esterzhou 已提交
1087 1088 1089 1090 1091

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | -------- | ---- | ------- | ------------------------------ |
E
ester.zhou 已提交
1092
| family | string   | Yes  | fantasy | Fantasy font family to set.|
E
esterzhou 已提交
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116

**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 已提交
1117
Sets the cursive font family for the web page.
E
esterzhou 已提交
1118 1119 1120 1121 1122

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | -------- | ---- | ------- | ------------------------------ |
E
ester.zhou 已提交
1123
| family | string   | Yes  | cursive | Cursive font family to set.|
E
esterzhou 已提交
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143

**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 已提交
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 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
### 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 已提交
1238
### allowWindowOpenMethod<sup>10+</sup>
E
ester.zhou 已提交
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251

allowWindowOpenMethod(flag: boolean)

Sets whether to allow a new window to automatically open through JavaScript.

When **flag** is set to **true**, a new window can automatically open through JavaScript. When **flag** is set to **false**, a new window can still automatically open through JavaScript for user behavior, but cannot for non-user behavior. The user behavior here refers to that a user requests to open a new window (**window.open**) within 5 seconds.

This API takes effect only when [javaScriptAccess](#javascriptaccess) is enabled.

This API opens a new window when [multiWindowAccess](#multiwindowaccess9) is enabled and opens a local window when [multiWindowAccess](#multiwindowaccess9) is disabled.

The default value of **flag** is subject to the settings of the **persist.web.allowWindowOpenMethod.enabled** system attribute. If this attribute is not set, the default value of **flag** is **false**.

E
ester.zhou 已提交
1252 1253 1254
To check the settings of **persist.web.allowWindowOpenMethod.enabled**,

run the **hdc shell param get persist.web.allowWindowOpenMethod.enabled** command. If the attribute is set to 0 or does not exist,
E
ester.zhou 已提交
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
you can run the **hdc shell param set persist.web.allowWindowOpenMethod.enabled 1** command to enable it.

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | ------- | ---- | ----- | ------------------ |
| flag | boolean | Yes  | Subject to the settings of the **persist.web.allowWindowOpenMethod.enabled** system attribute. If this attribute is set, the default value of **flag** is **true**. Otherwise, the default value of **flag** is **false**. | Whether to allow a new window to automatically open through JavaScript.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
E
ester.zhou 已提交
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
  // There are two <Web> components on the same page. When the WebComponent object opens a new window, the NewWebViewComp object is displayed. 
  @CustomDialog
  struct NewWebViewComp {
  controller: CustomDialogController
  webviewController1: web_webview.WebviewController
  build() {
      Column() {
        Web({ src: "", controller: this.webviewController1 })
          .javaScriptAccess(true)
          .multiWindowAccess(false)
          .onWindowExit(()=> {
            console.info("NewWebViewComp onWindowExit")
            this.controller.close()
          })
        }
    }
  }

E
ester.zhou 已提交
1286 1287 1288 1289
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
    dialogController: CustomDialogController = null
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          // MultiWindowAccess needs to be enabled.
          .multiWindowAccess(true)
          .allowWindowOpenMethod(true)
          .onWindowNew((event) => {
            if (this.dialogController) {
              this.dialogController.close()
            }
            let popController:web_webview.WebviewController = new web_webview.WebviewController()
            this.dialogController = new CustomDialogController({
              builder: NewWebViewComp({webviewController1: popController})
            })
            this.dialogController.open()
            // Return the WebviewController object corresponding to the new window to the <Web> kernel.
            // If opening a new window is not needed, set the parameter to null when calling the event.handler.setWebController API.
            // If the event.handler.setWebController API is not called, the render process will be blocked.
            event.handler.setWebController(popController)
          })
      }
    }
  }
  ```

### mediaOptions<sup>10+</sup>

mediaOptions(options: WebMediaOptions)

Sets the web-based media playback policy, including the validity period for automatically resuming a paused web audio, and whether the audio of multiple **\<Web>** instances in an application is exclusive.

> **NOTE**
>
> - Audios in the same **\<Web>** instance are considered as the same audio.
> - The media playback policy controls videos with an audio track.
> - After the parameter settings are updated, the playback must be started again for the settings to take effect.
> - It is recommended that you set the same **audioExclusive** value for all **\<Web>** components.

**Parameters**

| Name| Type| Mandatory| Default Value | Description                      |
| ------ | ----------- | ---- | --------------- | ------------------ |
| options | [WebMediaOptions](#webmediaoptions10) | Yes  | {resumeInterval: 0, audioExclusive: true} | Web-based media playback policy. The default value of **resumeInterval** is **0**, indicating that the playback is not automatically resumed.|

**Example**


  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State options: WebMediaOptions = {resumeInterval: 10, audioExclusive: true}
E
ester.zhou 已提交
1347 1348 1349
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
E
ester.zhou 已提交
1350
          .mediaOptions(this.options)
E
ester.zhou 已提交
1351 1352 1353 1354 1355
      }
    }
  }
  ```

E
ester.zhou 已提交
1356 1357
## Events

E
ester.zhou 已提交
1358
The universal events are not supported.
E
ester.zhou 已提交
1359

1360 1361 1362 1363
### onAlert

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

E
ester.zhou 已提交
1364
Called when **alert()** is invoked to display an alert dialog box on the web page.
1365 1366

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

1368 1369 1370 1371
| 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 已提交
1372
| result  | [JsResult](#jsresult) | User operation. |
1373 1374

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

1376 1377
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1378
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
1379 1380

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

1382 1383
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1384 1385
  import web_webview from '@ohos.web.webview'

1386 1387 1388
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1389
    controller: web_webview.WebviewController = new web_webview.WebviewController()
1390 1391
    build() {
      Column() {
E
ester.zhou 已提交
1392
        Web({ src: 'www.example.com', controller: this.controller })
1393 1394
          .onAlert((event) => {
            AlertDialog.show({
E
ester.zhou 已提交
1395
              title: 'onAlert',
1396
              message: 'text',
E
ester.zhou 已提交
1397 1398 1399 1400 1401 1402 1403 1404
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
1405 1406 1407 1408 1409 1410 1411 1412
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
E
ester.zhou 已提交
1413
            return true
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
          })
      }
    }
  }
  ```

### onBeforeUnload

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

E
ester.zhou 已提交
1424
Called when this page is about to exit after the user refreshes or closes the page. This API takes effect only when the page has obtained focus.
1425 1426

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

1428 1429 1430 1431
| 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 已提交
1432
| result  | [JsResult](#jsresult) | User operation. |
1433 1434

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

1436 1437
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1438
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
1439 1440

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

1442 1443
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1444 1445
  import web_webview from '@ohos.web.webview'

1446 1447 1448
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1449
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1450

1451 1452 1453 1454
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onBeforeUnload((event) => {
E
ester.zhou 已提交
1455 1456
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
E
ester.zhou 已提交
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475
            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 已提交
1476
            return true
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
          })
      }
    }
  }
  ```

### onConfirm

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

E
ester.zhou 已提交
1487
Called when **confirm()** is invoked by the web page.
1488 1489

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

1491 1492 1493 1494
| 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 已提交
1495
| result  | [JsResult](#jsresult) | User operation. |
1496 1497

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

1499 1500
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1501
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
1502 1503

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

1505 1506
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1507 1508
  import web_webview from '@ohos.web.webview'

1509 1510 1511
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1512
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1513

1514 1515 1516 1517
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onConfirm((event) => {
E
ester.zhou 已提交
1518 1519 1520
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
            console.log("event.result:" + event.result)
1521
            AlertDialog.show({
E
ester.zhou 已提交
1522
              title: 'onConfirm',
1523
              message: 'text',
E
ester.zhou 已提交
1524 1525 1526 1527 1528 1529 1530 1531
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
1532 1533 1534 1535 1536 1537 1538 1539
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
E
ester.zhou 已提交
1540
            return true
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551
          })
      }
    }
  }
  ```

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

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

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

1553 1554 1555 1556
| 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 已提交
1557
| result  | [JsResult](#jsresult) | User operation. |
1558 1559

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

1561 1562
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1563
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
1564 1565

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

1567 1568
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1569 1570
  import web_webview from '@ohos.web.webview'

1571 1572 1573
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1574
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1575

1576 1577
    build() {
      Column() {
E
ester.zhou 已提交
1578 1579
        Web({ src: 'www.example.com', controller: this.controller })
          .onPrompt((event) => {
E
ester.zhou 已提交
1580 1581 1582
            console.log("url:" + event.url)
            console.log("message:" + event.message)
            console.log("value:" + event.value)
E
ester.zhou 已提交
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
            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 已提交
1602
            return true
E
ester.zhou 已提交
1603 1604
          })
      }
1605 1606 1607 1608 1609 1610 1611 1612
    }
  }
  ```

### onConsole

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

E
ester.zhou 已提交
1613
Called to notify the host application of a JavaScript console message.
1614 1615

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

1617 1618 1619 1620 1621
| Name    | Type                             | Description     |
| ------- | --------------------------------- | --------- |
| message | [ConsoleMessage](#consolemessage) | Console message.|

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

1623 1624 1625 1626 1627
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the message will not be printed to the console; returns **false** otherwise.|

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

1629 1630
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1631 1632
  import web_webview from '@ohos.web.webview'

1633 1634 1635
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1636
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1637

1638 1639 1640 1641
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onConsole((event) => {
E
ester.zhou 已提交
1642 1643 1644 1645 1646
            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
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657
          })
      }
    }
  }
  ```

### onDownloadStart

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

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

1659 1660 1661 1662 1663 1664 1665 1666
| 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 已提交
1667

1668 1669
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1670 1671
  import web_webview from '@ohos.web.webview'

1672 1673 1674
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1675
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1676

1677 1678 1679 1680
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onDownloadStart((event) => {
E
ester.zhou 已提交
1681 1682 1683 1684 1685
            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)
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
          })
      }
    }
  }
  ```

### onErrorReceive

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

E
ester.zhou 已提交
1696
Called when an error occurs during web page loading. For better results, simplify the implementation logic in the callback. This API is called when there is no network connection.
1697 1698

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

1700 1701 1702 1703 1704 1705
| 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 已提交
1706

1707 1708
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1709 1710
  import web_webview from '@ohos.web.webview'

1711 1712 1713
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1714
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1715

1716 1717 1718 1719
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onErrorReceive((event) => {
E
ester.zhou 已提交
1720 1721 1722 1723 1724 1725 1726 1727 1728
            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)
1729
            for (let i of result) {
E
ester.zhou 已提交
1730
              console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue)
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
            }
          })
      }
    }
  }
  ```

### onHttpErrorReceive

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

E
ester.zhou 已提交
1742
Called when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading.
1743 1744

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

1746 1747 1748
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
E
ester.zhou 已提交
1749
| response | [WebResourceResponse](#webresourceresponse)    | Encapsulation of a resource response.|
1750 1751

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

1753 1754
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1755 1756
  import web_webview from '@ohos.web.webview'

1757 1758 1759
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1760
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1761

1762 1763 1764 1765
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpErrorReceive((event) => {
E
ester.zhou 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
            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)
1777
            for (let i of result) {
E
ester.zhou 已提交
1778
              console.log('The request header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
1779
            }
E
ester.zhou 已提交
1780 1781
            let resph = event.response.getResponseHeader()
            console.log('The response header result size is ' + resph.length)
1782
            for (let i of resph) {
E
ester.zhou 已提交
1783
              console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
            }
          })
      }
    }
  }
  ```

### onPageBegin

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


E
ester.zhou 已提交
1796
Called when the web page starts to be loaded. This API is called only for the main frame content, and not for the iframe or frameset content.
1797 1798

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

1800 1801 1802 1803 1804
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

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

1806 1807
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1808 1809
  import web_webview from '@ohos.web.webview'

1810 1811 1812
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1813
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1814

1815 1816 1817 1818
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPageBegin((event) => {
E
ester.zhou 已提交
1819
            console.log('url:' + event.url)
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
          })
      }
    }
  }
  ```

### onPageEnd

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


E
ester.zhou 已提交
1831
Called when the web page loading is complete. This API takes effect only for the main frame content.
1832 1833

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

1835 1836 1837 1838 1839
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

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

1841 1842
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1843 1844
  import web_webview from '@ohos.web.webview'

1845 1846 1847
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1848
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1849

1850 1851 1852 1853
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPageEnd((event) => {
E
ester.zhou 已提交
1854
            console.log('url:' + event.url)
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
          })
      }
    }
  }
  ```

### onProgressChange

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

E
ester.zhou 已提交
1865
Called when the web page loading progress changes.
1866 1867

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

1869 1870 1871 1872
| Name        | Type  | Description                 |
| ----------- | ------ | --------------------- |
| newProgress | number | New loading progress. The value is an integer ranging from 0 to 100.|

E
ester.zhou 已提交
1873 1874
**Example**

1875 1876
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1877 1878
  import web_webview from '@ohos.web.webview'

1879 1880 1881
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1882
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1883

1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onProgressChange((event) => {
            console.log('newProgress:' + event.newProgress)
          })
      }
    }
  }
  ```

### onTitleReceive

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

E
ester.zhou 已提交
1899
Called when the document title of the web page is changed.
1900 1901

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

1903 1904 1905 1906
| Name  | Type  | Description         |
| ----- | ------ | ------------- |
| title | string | Document title.|

E
ester.zhou 已提交
1907 1908
**Example**

1909 1910
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1911 1912
  import web_webview from '@ohos.web.webview'

1913 1914 1915
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1916
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1917

1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
    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)

E
ester.zhou 已提交
1933
Called when loading of the web page is complete. This API is used by an application to update the historical link it accessed.
1934 1935

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

E
ester.zhou 已提交
1937 1938 1939
| Name        | Type   | Description                                    |
| ----------- | ------- | ---------------------------------------- |
| url         | string  | URL to be accessed.                                 |
E
ester.zhou 已提交
1940 1941 1942
| 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**
1943 1944 1945

  ```ts
  // xxx.ets
E
ester.zhou 已提交
1946 1947
  import web_webview from '@ohos.web.webview'

1948 1949 1950
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1951
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1952

1953 1954 1955 1956
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onRefreshAccessedHistory((event) => {
E
ester.zhou 已提交
1957
            console.log('url:' + event.url + ' isReload:' + event.isRefreshed)
1958 1959 1960 1961 1962 1963
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1964
### onRenderExited<sup>9+</sup>
1965 1966 1967

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

E
ester.zhou 已提交
1968
Called when the rendering process exits abnormally.
1969 1970

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

1972 1973 1974 1975
| Name             | Type                                    | Description            |
| ---------------- | ---------------------------------------- | ---------------- |
| renderExitReason | [RenderExitReason](#renderexitreason)| Cause for the abnormal exit of the rendering process.|

E
ester.zhou 已提交
1976 1977
**Example**

1978 1979
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1980 1981
  import web_webview from '@ohos.web.webview'

1982 1983 1984
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1985
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1986

1987 1988 1989 1990
    build() {
      Column() {
        Web({ src: 'chrome://crash/', controller: this.controller })
          .onRenderExited((event) => {
E
ester.zhou 已提交
1991
            console.log('reason:' + event.renderExitReason)
1992 1993 1994 1995 1996 1997 1998 1999
          })
      }
    }
  }
  ```

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

E
ester.zhou 已提交
2000
onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector: FileSelectorParam }) => boolean)
2001

E
ester.zhou 已提交
2002
Called to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.
2003 2004

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

2006 2007 2008 2009 2010
| 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 已提交
2011 2012
**Return value**

E
ester.zhou 已提交
2013 2014
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
2015
| boolean | The value **true** means that the pop-up window provided by the system is displayed. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
E
ester.zhou 已提交
2016 2017 2018 2019

**Example**

  ```ts
2020
  // xxx.ets
E
ester.zhou 已提交
2021 2022
  import web_webview from '@ohos.web.webview'

2023 2024 2025
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2026
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048

    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 已提交
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
            return true
          })
      }
    }
  }
  ```

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

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

E
ester.zhou 已提交
2060
Called to notify the **\<Web>** component of the URL of the loaded resource file.
E
ester.zhou 已提交
2061 2062 2063

**Parameters**

E
ester.zhou 已提交
2064 2065 2066
| Name | Type  | Description          |
| ---- | ------ | -------------- |
| url  | string | URL of the loaded resource file.|
E
ester.zhou 已提交
2067 2068 2069 2070 2071

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2072 2073
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2074 2075 2076
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2077
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2078

E
ester.zhou 已提交
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093
    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)

E
ester.zhou 已提交
2094
Called when the display ratio of this page changes.
E
ester.zhou 已提交
2095 2096 2097

**Parameters**

E
ester.zhou 已提交
2098 2099
| Name     | Type  | Description        |
| -------- | ------ | ------------ |
E
ester.zhou 已提交
2100 2101 2102 2103 2104 2105 2106
| oldScale | number | Display ratio of the page before the change.|
| newScale | number | Display ratio of the page after the change.|

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2107 2108
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2109 2110 2111
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2112
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2113

E
ester.zhou 已提交
2114 2115 2116 2117 2118
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onScaleChange((event) => {
            console.log('onScaleChange changed from ' + event.oldScale + ' to ' + event.newScale)
2119 2120 2121 2122 2123 2124
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
2125
### onUrlLoadIntercept<sup>(deprecated)</sup>
2126 2127 2128

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

E
ester.zhou 已提交
2129
Called when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access, which is allowed by default.
E
ester.zhou 已提交
2130
This API is deprecated since API version 10. You are advised to use [onLoadIntercept<sup>10+</sup>](#onloadintercept10) instead.
2131 2132

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

2134 2135 2136 2137 2138
| Name | Type                                    | Description     |
| ---- | ---------------------------------------- | --------- |
| data | string / [WebResourceRequest](#webresourcerequest) | URL information.|

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

2140 2141 2142 2143 2144 2145 2146 2147
| Type     | Description                      |
| ------- | ------------------------ |
| boolean | Returns **true** if the access is blocked; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2148 2149
  import web_webview from '@ohos.web.webview'

2150 2151 2152
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2153
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2154

2155 2156 2157 2158 2159
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onUrlLoadIntercept((event) => {
            console.log('onUrlLoadIntercept ' + event.data.toString())
E
ester.zhou 已提交
2160
            return true
2161 2162 2163 2164 2165 2166 2167 2168
          })
      }
    }
  }
  ```

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

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

E
ester.zhou 已提交
2171
Called when the **\<Web>** component is about to access a URL. This API is used to block the URL and return the response data.
2172 2173

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

2175 2176 2177 2178 2179
| Name    | Type                                    | Description       |
| ------- | ---------------------------------------- | ----------- |
| request | [WebResourceRequest](#webresourcerequest) | Information about the URL request.|

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

E
ester.zhou 已提交
2181 2182
| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
E
ester.zhou 已提交
2183 2184 2185
| [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**
2186 2187 2188

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2189 2190
  import web_webview from '@ohos.web.webview'

2191 2192 2193
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2194
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2195 2196
    responseweb: WebResourceResponse = new WebResourceResponse()
    heads:Header[] = new Array()
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207
    @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 已提交
2208
        Web({ src: 'www.example.com', controller: this.controller })
2209
          .onInterceptRequest((event) => {
E
ester.zhou 已提交
2210
            console.log('url:' + event.request.getRequestUrl())
2211 2212 2213 2214 2215 2216 2217 2218
            var head1:Header = {
              headerKey:"Connection",
              headerValue:"keep-alive"
            }
            var head2:Header = {
              headerKey:"Cache-Control",
              headerValue:"no-cache"
            }
E
ester.zhou 已提交
2219 2220 2221 2222 2223 2224 2225 2226 2227
            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
2228 2229 2230 2231 2232 2233 2234 2235 2236 2237
          })
      }
    }
  }
  ```

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

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

E
ester.zhou 已提交
2238
Called when an HTTP authentication request is received.
2239 2240

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

2242 2243
| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
E
ester.zhou 已提交
2244
| handler | [HttpAuthHandler](#httpauthhandler9) | User operation.  |
2245 2246 2247 2248
| host    | string                               | Host to which HTTP authentication credentials apply.|
| realm   | string                               | Realm to which HTTP authentication credentials apply. |

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

2250 2251
| Type     | Description                   |
| ------- | --------------------- |
E
ester.zhou 已提交
2252
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|
2253 2254 2255 2256 2257

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2258
  import web_webview from '@ohos.web.webview'
2259 2260 2261
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2262
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2263
    httpAuth: boolean = false
E
ester.zhou 已提交
2264

2265 2266
    build() {
      Column() {
E
ester.zhou 已提交
2267 2268 2269 2270 2271 2272 2273 2274
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpAuthRequest((event) => {
            AlertDialog.show({
              title: 'onHttpAuthRequest',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
E
ester.zhou 已提交
2275
                  event.handler.cancel()
2276
                }
E
ester.zhou 已提交
2277 2278 2279 2280
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
E
ester.zhou 已提交
2281
                  this.httpAuth = event.handler.isHttpAuthInfoSaved()
E
ester.zhou 已提交
2282 2283 2284 2285 2286 2287 2288
                  if (this.httpAuth == false) {
                    web_webview.WebDataBase.saveHttpAuthCredentials(
                      event.host,
                      event.realm,
                      "2222",
                      "2222"
                    )
E
ester.zhou 已提交
2289
                    event.handler.cancel()
E
ester.zhou 已提交
2290 2291 2292 2293
                  }
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2294
                event.handler.cancel()
2295
              }
E
ester.zhou 已提交
2296
            })
E
ester.zhou 已提交
2297
            return true
2298
          })
E
ester.zhou 已提交
2299 2300 2301 2302 2303 2304 2305 2306
      }
    }
  }
  ```
### onSslErrorEventReceive<sup>9+</sup>

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

E
ester.zhou 已提交
2307
Called when an SSL error occurs during resource loading.
E
ester.zhou 已提交
2308 2309 2310

**Parameters**

E
ester.zhou 已提交
2311 2312
| Name    | Type                                | Description          |
| ------- | ------------------------------------ | -------------- |
E
ester.zhou 已提交
2313
| handler | [SslErrorHandler](#sslerrorhandler9) | User operation.|
E
ester.zhou 已提交
2314
| error   | [SslError](#sslerror9)          | Error code.          |
E
ester.zhou 已提交
2315 2316 2317 2318 2319 2320 2321 2322 2323

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2324
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2325

E
ester.zhou 已提交
2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
    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 已提交
2336
                  event.handler.handleConfirm()
E
ester.zhou 已提交
2337 2338 2339 2340 2341
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
E
ester.zhou 已提交
2342
                  event.handler.handleCancel()
E
ester.zhou 已提交
2343 2344 2345
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2346
                event.handler.handleCancel()
E
ester.zhou 已提交
2347 2348
              }
            })
E
ester.zhou 已提交
2349
            return true
E
ester.zhou 已提交
2350 2351 2352 2353 2354 2355 2356 2357
          })
      }
    }
  }
  ```

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

E
ester.zhou 已提交
2358
onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array<string>, issuers : Array<string>}) => void)
E
ester.zhou 已提交
2359

E
ester.zhou 已提交
2360
Called when an SSL client certificate request is received.
E
ester.zhou 已提交
2361 2362 2363

**Parameters**

E
ester.zhou 已提交
2364 2365
| Name     | Type                                    | Description           |
| -------- | ---------------------------------------- | --------------- |
E
ester.zhou 已提交
2366
| handler  | [ClientAuthenticationHandler](#clientauthenticationhandler9) | User operation. |
E
ester.zhou 已提交
2367 2368
| 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 已提交
2369 2370
| keyTypes | Array<string>                            | Acceptable asymmetric private key types.   |
| issuers  | Array<string>                            | Issuer of the certificate that matches the private key.|
E
ester.zhou 已提交
2371 2372 2373

  **Example**
  ```ts
E
ester.zhou 已提交
2374
  // xxx.ets API9
E
ester.zhou 已提交
2375 2376 2377 2378
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2379
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390

    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 已提交
2391
                  event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem")
E
ester.zhou 已提交
2392 2393 2394 2395 2396
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
E
ester.zhou 已提交
2397
                  event.handler.cancel()
E
ester.zhou 已提交
2398 2399 2400
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2401
                event.handler.ignore()
E
ester.zhou 已提交
2402 2403
              }
            })
E
ester.zhou 已提交
2404
            return true
E
ester.zhou 已提交
2405 2406
          })
      }
2407 2408 2409
    }
  }
  ```
E
ester.zhou 已提交
2410

E
ester.zhou 已提交
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 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510
  ```ts
  // xxx.ets API10
  import web_webview from '@ohos.web.webview'
  import bundle from '@ohos.bundle'

  let uri = "";

  export default class CertManagerService {
    private static sInstance: CertManagerService;
    private authUri = "";

    public static getInstance(): CertManagerService {
      if (CertManagerService.sInstance == null) {
        CertManagerService.sInstance = new CertManagerService();
      }
      return CertManagerService.sInstance;
    }

    async grantAppPm(callback) {
      let message = '';
      // Note: Replace com.example.myapplication with the actual application name.
      let bundleInfo = await bundle.getBundleInfo("com.example.myapplication", bundle.BundleFlag.GET_BUNDLE_DEFAULT)
      let clientAppUid = bundleInfo.uid
      let appUid = clientAppUid.toString()

      // Note: For globalThis.AbilityContext, add globalThis.AbilityContext = this.context to the onCreate function in the MainAbility.ts file.
      await globalThis.AbilityContext.startAbilityForResult(
        {
          bundleName: "com.ohos.certmanager",
          abilityName: "MainAbility",
          uri: "requestAuthorize",
          parameters: {
            appUid: appUid, // UID of the requesting application.
          }
        })
        .then((data) => {
          if (!data.resultCode) {
            this.authUri = data.want.parameters.authUri; // Value of authUri returned when authorization is successful.
          }
        })
      message += "after grantAppPm authUri: " + this.authUri;
      uri = this.authUri;
      callback(message)
    }
  }

  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController();
    @State message: string ='Hello World' // message is used for debugging and observation.
    certManager = CertManagerService.getInstance();

    build() {
      Row() {
        Column() {
          Row() {
            // Step 1: Perform authorization to obtain the URI.
            Button('GrantApp')
              .onClick(() => {
                this.certManager.grantAppPm((data) => {
                  this.message = data;
                });
              })
            // Step 2: After the authorization, in two-way authentication, the onClientAuthenticationRequest callback is used to send the URI to the web server for authentication.
            Button("ClientCertAuth")
              .onClick(() => {
                this.controller.loadUrl('https://www.example2.com'); // Server website that supports two-way authentication.
              })
          }

          Web({ src: 'https://www.example1.com', controller: this.controller })
            .fileAccess(true)
            .javaScriptAccess(true)
            .domStorageAccess(true)
            .onlineImageAccess(true)

          .onClientAuthenticationRequest((event) => {
            AlertDialog.show({
              title: 'ClientAuth',
              message: 'Text',
              confirm: {
                value: 'Confirm',
                action: () => {
                  event.handler.confirm(uri);
                }
              },
              cancel: () => {
                event.handler.cancel();
              }
            })
          })
        }
      }
      .width('100%')
      .height('100%')
    }
  }
  ```

2511 2512 2513 2514
### onPermissionRequest<sup>9+</sup>

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

E
ester.zhou 已提交
2515
Called when a permission request is received.
2516 2517

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

E
ester.zhou 已提交
2519 2520
| Name    | Type                                    | Description          |
| ------- | ---------------------------------------- | -------------- |
E
ester.zhou 已提交
2521
| request | [PermissionRequest](#permissionrequest9) | User operation.|
2522

E
ester.zhou 已提交
2523 2524 2525 2526
**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2527 2528
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2529 2530 2531
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2532
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2533 2534 2535 2536 2537 2538 2539 2540 2541 2542
    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 已提交
2543
                  event.request.deny()
E
ester.zhou 已提交
2544 2545 2546 2547 2548
                }
              },
              secondaryButton: {
                value: 'onConfirm',
                action: () => {
E
ester.zhou 已提交
2549
                  event.request.grant(event.request.getAccessibleResource())
E
ester.zhou 已提交
2550 2551 2552
                }
              },
              cancel: () => {
E
ester.zhou 已提交
2553
                event.request.deny()
E
ester.zhou 已提交
2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565
              }
            })
          })
      }
    }
  }
  ```

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

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

E
ester.zhou 已提交
2566
Called when a context menu is displayed after the user clicks the right mouse button or long presses a specific element, such as an image or a link.
E
ester.zhou 已提交
2567 2568 2569

**Parameters**

E
ester.zhou 已提交
2570 2571 2572 2573
| Name   | Type                                    | Description       |
| ------ | ---------------------------------------- | ----------- |
| param  | [WebContextMenuParam](#webcontextmenuparam9) | Parameters related to the context menu.    |
| result | [WebContextMenuResult](#webcontextmenuresult9) | Result of the context menu.|
E
ester.zhou 已提交
2574 2575 2576

**Return value**

E
ester.zhou 已提交
2577 2578
| Type     | Description                      |
| ------- | ------------------------ |
E
ester.zhou 已提交
2579 2580 2581 2582 2583 2584
| boolean | The value **true** means a custom menu, and **false** means the default menu.|

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2585 2586
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2587 2588 2589
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2590
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607
    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)

E
ester.zhou 已提交
2608
Called when the scrollbar of the page scrolls.
E
ester.zhou 已提交
2609 2610 2611

**Parameters**

E
ester.zhou 已提交
2612 2613
| Name    | Type  | Description        |
| ------- | ------ | ------------ |
E
ester.zhou 已提交
2614 2615
| xOffset | number | Position of the scrollbar on the x-axis relative to the leftmost of the web page.|
| yOffset | number | Position of the scrollbar on the y-axis relative to the top of the web page.|
E
ester.zhou 已提交
2616 2617 2618 2619 2620

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2621 2622
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2623 2624 2625
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2626
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642
    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)

E
ester.zhou 已提交
2643
Called when a request to obtain the geolocation information is received.
E
ester.zhou 已提交
2644 2645 2646

**Parameters**

E
ester.zhou 已提交
2647 2648
| Name        | Type                           | Description          |
| ----------- | ------------------------------- | -------------- |
E
ester.zhou 已提交
2649
| origin      | string                          | Index of the origin.    |
E
ester.zhou 已提交
2650
| geolocation | [JsGeolocation](#jsgeolocation) | User operation.|
E
ester.zhou 已提交
2651 2652 2653 2654 2655

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2656 2657
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2658 2659 2660
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2661
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
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
    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)

E
ester.zhou 已提交
2690
Called to notify the user that the request for obtaining the geolocation information received when **[onGeolocationShow](#ongeolocationshow)** is called has been canceled.
E
ester.zhou 已提交
2691 2692 2693

**Parameters**

E
ester.zhou 已提交
2694 2695 2696
| Name     | Type      | Description                |
| -------- | ---------- | -------------------- |
| callback | () => void | Callback invoked when the request for obtaining geolocation information has been canceled. |
E
ester.zhou 已提交
2697 2698 2699 2700 2701

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2702 2703
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2704 2705 2706
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2707
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723
    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)

E
ester.zhou 已提交
2724
Called when the component enters full screen mode.
E
ester.zhou 已提交
2725 2726 2727

**Parameters**

E
ester.zhou 已提交
2728 2729 2730
| Name    | Type                                    | Description          |
| ------- | ---------------------------------------- | -------------- |
| handler | [FullScreenExitHandler](#fullscreenexithandler9) | Function handle for exiting full screen mode.|
E
ester.zhou 已提交
2731 2732 2733 2734 2735

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2736 2737
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2738 2739 2740
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2741
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755
    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 已提交
2756

E
ester.zhou 已提交
2757
onFullScreenExit(callback: () => void)
E
ester.zhou 已提交
2758

E
ester.zhou 已提交
2759
Called when the component exits full screen mode.
E
ester.zhou 已提交
2760

E
ester.zhou 已提交
2761
**Parameters**
E
ester.zhou 已提交
2762

E
ester.zhou 已提交
2763 2764 2765
| Name     | Type      | Description         |
| -------- | ---------- | ------------- |
| callback | () => void | Callback invoked when the component exits full screen mode.|
E
ester.zhou 已提交
2766 2767 2768 2769 2770

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2771 2772
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2773 2774 2775
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2776
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2777
    handler: FullScreenExitHandler = null
E
ester.zhou 已提交
2778 2779
    build() {
      Column() {
E
ester.zhou 已提交
2780 2781 2782 2783 2784 2785 2786
        Web({ src:'www.example.com', controller:this.controller })
        .onFullScreenExit(() => {
          console.log("onFullScreenExit...")
          this.handler.exitFullScreen()
        })
        .onFullScreenEnter((event) => {
          this.handler = event.handler
E
ester.zhou 已提交
2787 2788 2789 2790 2791 2792
        })
      }
    }
  }
  ```

E
ester.zhou 已提交
2793
### onWindowNew<sup>9+</sup>
E
ester.zhou 已提交
2794

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

E
ester.zhou 已提交
2797 2798 2799
Called when a new window is created. This API takes effect when **multiWindowAccess** is enabled.
If the **event.handler.setWebController** API is not called, the render process will be blocked.
If opening a new window is not needed, set the parameter to **null** when calling the **event.handler.setWebController** API.
E
ester.zhou 已提交
2800 2801 2802

**Parameters**

E
ester.zhou 已提交
2803 2804 2805 2806 2807
| 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.                    |
E
ester.zhou 已提交
2808
| handler       | [ControllerHandler](#controllerhandler9) | **WebviewController** instance for setting the new window. |
E
ester.zhou 已提交
2809 2810 2811 2812 2813

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2814
  import web_webview from '@ohos.web.webview'
E
ester.zhou 已提交
2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833
  
  // There are two <Web> components on the same page. When the WebComponent object opens a new window, the NewWebViewComp object is displayed. 
  @CustomDialog
  struct NewWebViewComp {
  controller: CustomDialogController
  webviewController1: web_webview.WebviewController
  build() {
      Column() {
        Web({ src: "", controller: this.webviewController1 })
          .javaScriptAccess(true)
          .multiWindowAccess(false)
          .onWindowExit(()=> {
            console.info("NewWebViewComp onWindowExit")
            this.controller.close()
          })
        }
    }
  }

E
ester.zhou 已提交
2834 2835 2836
  @Entry
  @Component
  struct WebComponent {
E
esterzhou 已提交
2837
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2838
    dialogController: CustomDialogController = null
E
ester.zhou 已提交
2839 2840
    build() {
      Column() {
E
ester.zhou 已提交
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          // MultiWindowAccess needs to be enabled.
          .multiWindowAccess(true)
          .allowWindowOpenMethod(true)
          .onWindowNew((event) => {
            if (this.dialogController) {
              this.dialogController.close()
            }
            let popController:web_webview.WebviewController = new web_webview.WebviewController()
            this.dialogController = new CustomDialogController({
              builder: NewWebViewComp({webviewController1: popController})
            })
            this.dialogController.open()
            // Return the WebviewController object corresponding to the new window to the <Web> kernel.
            // If opening a new window is not needed, set the parameter to null when calling the event.handler.setWebController API.
            // If the event.handler.setWebController API is not called, the render process will be blocked.
            event.handler.setWebController(popController)
          })
E
ester.zhou 已提交
2860 2861 2862 2863 2864
      }
    }
  }
  ```

E
ester.zhou 已提交
2865
### onWindowExit<sup>9+</sup>
E
ester.zhou 已提交
2866

E
ester.zhou 已提交
2867
onWindowExit(callback: () => void)
E
ester.zhou 已提交
2868

E
ester.zhou 已提交
2869
Called when this window is closed.
E
ester.zhou 已提交
2870 2871 2872

**Parameters**

E
ester.zhou 已提交
2873 2874
| Name     | Type      | Description        |
| -------- | ---------- | ------------ |
E
ester.zhou 已提交
2875
| callback | () => void | Callback invoked when the window is closed.|
E
ester.zhou 已提交
2876

2877 2878 2879 2880
**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
2881 2882
  import web_webview from '@ohos.web.webview'

2883 2884 2885
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2886
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2887 2888
    build() {
      Column() {
E
ester.zhou 已提交
2889 2890 2891
        Web({ src:'www.example.com', controller: this.controller })
        .onWindowExit(() => {
          console.log("onWindowExit...")
2892
        })
E
ester.zhou 已提交
2893
      }
2894 2895 2896 2897
    }
  }
  ```

E
ester.zhou 已提交
2898 2899 2900 2901
### onSearchResultReceive<sup>9+</sup>

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

E
ester.zhou 已提交
2902
Called to notify the caller of the search result on the web page.
E
ester.zhou 已提交
2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915

**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
E
ester.zhou 已提交
2916 2917
  import web_webview from '@ohos.web.webview'

E
ester.zhou 已提交
2918 2919 2920
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2921
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934

    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 已提交
2935 2936 2937 2938
### onDataResubmitted<sup>9+</sup>

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

E
ester.zhou 已提交
2939
Called when the web form data is resubmitted.
E
esterzhou 已提交
2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971

**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)

E
ester.zhou 已提交
2972
Called when the old page is not displayed and the new page is about to be visible.
E
esterzhou 已提交
2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003

**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)

E
ester.zhou 已提交
3004
Called when the key event is intercepted and before it is consumed by the webview.
E
esterzhou 已提交
3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015

**Parameters**

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

**Return value**

| Type   | Description                                                        |
| ------- | ------------------------------------------------------------ |
E
ester.zhou 已提交
3016
| boolean | Whether to continue to transfer the key event to the webview kernel.|
E
esterzhou 已提交
3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030

**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) => {
E
ester.zhou 已提交
3031
          if (event.keyCode == 2017 || event.keyCode == 2018) {
E
esterzhou 已提交
3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045
            console.info(`onInterceptKeyEvent get event.keyCode ${event.keyCode}`)
            return true;
          }
          return false;
        })
      }
    }
  }
  ```

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

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

E
ester.zhou 已提交
3046
Called when an apple-touch-icon URL is received.
E
esterzhou 已提交
3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078

**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)

E
ester.zhou 已提交
3079
Called when this web page receives a new favicon.
E
esterzhou 已提交
3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109

**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;
        })
      }
    }
  }
  ```

E
ester.zhou 已提交
3110 3111 3112 3113
### onAudioStateChanged<sup>10+</sup>

onAudioStateChanged(callback: (event: { playing: boolean }) => void)

E
ester.zhou 已提交
3114
Called when the audio playback status changes on the web page.
E
ester.zhou 已提交
3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143

**Parameters**

| Name | Type                                      | Description                           |
| ------- | ---------------------------------------------- | ----------------------------------- |
| playing | boolean | Audio playback status on the current page. The value **true** means that audio is being played, and **false** means the opposite.|

**Example**

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

E
ester.zhou 已提交
3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179
### onFirstContentfulPaint<sup>10+</sup>

onFirstContentfulPaint(callback: (event?: { navigationStartTick: number, firstContentfulPaintMs: number }) => void)

Called when the web page content is first rendered.

**Parameters**

| Name                |  Type | Description                           |
| -----------------------| -------- | ----------------------------------- |
| navigationStartTick    | number   | Navigation start time, in microseconds.|
| firstContentfulPaintMs | number   | Time between navigation and when the content is first rendered, in milliseconds.|

**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 })
          .onFirstContentfulPaint(event => {
            console.log("onFirstContentfulPaint:" + "[navigationStartTick]:" + 
              event.navigationStartTick + ", [firstContentfulPaintMs]:" + 
              event.firstContentfulPaintMs)
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
3180 3181
### onLoadIntercept<sup>10+</sup>

E
ester.zhou 已提交
3182
onLoadIntercept(callback: (event?: { data: WebResourceRequest }) => boolean)
E
ester.zhou 已提交
3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211

Called when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access, which is allowed by default.

**Parameters**

| Name | Type                                    | Description     |
| ------- | ---------------------------------------- | --------- |
| request | [Webresourcerequest](#webresourcerequest) | Information about the URL request.|

**Return value**

| Type     | Description                      |
| ------- | ------------------------ |
| boolean | Returns **true** if the access is blocked; returns **false** otherwise.|

**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 })
E
ester.zhou 已提交
3212 3213 3214 3215 3216
          .onLoadIntercept((event) => {
            console.log('url:' + event.data.getRequestUrl())
            console.log('isMainFrame:' + event.data.isMainFrame())
            console.log('isRedirect:' + event.data.isRedirect())
            console.log('isRequestGesture:' + event.data.isRequestGesture())
E
ester.zhou 已提交
3217 3218 3219 3220 3221 3222 3223
            return true
          })
      }
    }
  }
  ```

3224 3225
## ConsoleMessage

E
esterzhou 已提交
3226
Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole).
3227 3228 3229 3230 3231 3232 3233 3234

### getLineNumber

getLineNumber(): number

Obtains the number of rows in this console message.

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

3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246
| 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 已提交
3247

3248 3249
| Type    | Description                    |
| ------ | ---------------------- |
E
ester.zhou 已提交
3250
| string | Log information of the console message.|
3251 3252 3253 3254 3255 3256 3257 3258

### getMessageLevel

getMessageLevel(): MessageLevel

Obtains the level of this console message.

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

3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270
| 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 已提交
3271

3272 3273 3274 3275 3276 3277
| Type    | Description           |
| ------ | ------------- |
| string | Path and name of the web page source file.|

## JsResult

E
ester.zhou 已提交
3278
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](#onalert).
3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298

### 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 已提交
3299

3300 3301 3302 3303
| Name   | Type  | Mandatory  | Default Value | Description       |
| ------ | ------ | ---- | ---- | ----------- |
| result | string | Yes   | -    | User input in the dialog box.|

E
ester.zhou 已提交
3304 3305
## FullScreenExitHandler<sup>9+</sup>

E
ester.zhou 已提交
3306
Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9).
E
ester.zhou 已提交
3307 3308 3309 3310 3311 3312 3313 3314 3315

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

exitFullScreen(): void

Exits full screen mode.

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

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

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

E
esterzhou 已提交
3320
setWebController(controller: WebviewController): void
E
ester.zhou 已提交
3321

E
ester.zhou 已提交
3322
Sets a **WebviewController** object. If opening a new window is not needed, set the parameter to **null**.
E
ester.zhou 已提交
3323 3324 3325

**Parameters**

E
ester.zhou 已提交
3326 3327
| Name       | Type         | Mandatory  | Default Value | Description                     |
| ---------- | ------------- | ---- | ---- | ------------------------- |
E
ester.zhou 已提交
3328
| controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes   | -    | **WebviewController** object of the **\<Web>** component. If opening a new window is not needed, set it to **null**.|
E
ester.zhou 已提交
3329

3330 3331
## WebResourceError

E
esterzhou 已提交
3332
Implements the **WebResourceError** object. For the sample code, see [onErrorReceive](#onerrorreceive).
3333 3334 3335 3336 3337 3338 3339 3340

### getErrorCode

getErrorCode(): number

Obtains the error code for resource loading.

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

3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352
| Type    | Description         |
| ------ | ----------- |
| number | Error code for resource loading.|

### getErrorInfo

getErrorInfo(): string

Obtains error information about resource loading.

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

3354 3355 3356 3357 3358 3359
| Type    | Description          |
| ------ | ------------ |
| string | Error information about resource loading.|

## WebResourceRequest

E
esterzhou 已提交
3360
Implements the **WebResourceRequest** object. For the sample code, see [onErrorReceive](#onerrorreceive).
3361 3362 3363 3364 3365 3366 3367 3368

### getRequestHeader

getResponseHeader() : Array\<Header\>

Obtains the information about the resource request header.

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

3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380
| 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 已提交
3381

3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392
| 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 已提交
3393

3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404
| 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 已提交
3405

3406 3407
| Type     | Description              |
| ------- | ---------------- |
E
ester.zhou 已提交
3408
| boolean | Whether the resource request is redirected by the server.|
3409 3410 3411 3412 3413 3414 3415 3416

### isRequestGesture

isRequestGesture(): boolean

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

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

3418 3419
| Type     | Description                  |
| ------- | -------------------- |
E
ester.zhou 已提交
3420
| boolean | Whether the resource request is associated with a gesture (for example, a tap).|
3421

E
ester.zhou 已提交
3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433
### getRequestMethod<sup>9+</sup>

getRequestMethod(): string

Obtains the request method.

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| string | Request method.|

3434
## Header
E
ester.zhou 已提交
3435

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

3438 3439 3440 3441
| Name         | Type    | Description           |
| ----------- | ------ | ------------- |
| headerKey   | string | Key of the request/response header.  |
| headerValue | string | Value of the request/response header.|
E
ester.zhou 已提交
3442 3443


3444
## WebResourceResponse
E
ester.zhou 已提交
3445

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

3448
### getReasonMessage
E
ester.zhou 已提交
3449

3450
getReasonMessage(): string
E
ester.zhou 已提交
3451

3452
Obtains the status code description of the resource response.
E
ester.zhou 已提交
3453

3454
**Return value**
E
ester.zhou 已提交
3455

3456 3457 3458
| Type    | Description           |
| ------ | ------------- |
| string | Status code description of the resource response.|
E
ester.zhou 已提交
3459

3460
### getResponseCode
E
ester.zhou 已提交
3461

3462
getResponseCode(): number
E
ester.zhou 已提交
3463

3464
Obtains the status code of the resource response.
E
ester.zhou 已提交
3465

3466
**Return value**
E
ester.zhou 已提交
3467

3468 3469 3470
| Type    | Description         |
| ------ | ----------- |
| number | Status code of the resource response.|
E
ester.zhou 已提交
3471

3472
### getResponseData
E
ester.zhou 已提交
3473

3474
getResponseData(): string
E
ester.zhou 已提交
3475

3476
Obtains the data in the resource response.
E
ester.zhou 已提交
3477

3478
**Return value**
E
ester.zhou 已提交
3479

3480 3481 3482
| Type    | Description       |
| ------ | --------- |
| string | Data in the resource response.|
E
ester.zhou 已提交
3483

3484
### getResponseEncoding
E
ester.zhou 已提交
3485

3486 3487 3488 3489 3490
getResponseEncoding(): string

Obtains the encoding string of the resource response.

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

3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502
| Type    | Description        |
| ------ | ---------- |
| string | Encoding string of the resource response.|

### getResponseHeader

getResponseHeader() : Array\<Header\>

Obtains the resource response header.

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

3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514
| Type                        | Description      |
| -------------------------- | -------- |
| Array\<[Header](#header)\> | Resource response header.|

### getResponseMimeType

getResponseMimeType(): string

Obtains the MIME type of the resource response.

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

3516 3517 3518 3519 3520 3521
| Type    | Description                |
| ------ | ------------------ |
| string | MIME type of the resource response.|

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

E
ester.zhou 已提交
3522
setResponseData(data: string | number)
3523 3524 3525 3526

Sets the data in the resource response.

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

E
ester.zhou 已提交
3528 3529 3530
| 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.|
3531 3532 3533 3534 3535 3536 3537 3538

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

setResponseEncoding(encoding: string)

Sets the encoding string of the resource response.

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

3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550
| 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 已提交
3551

3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562
| 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 已提交
3563

3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574
| 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 已提交
3575

3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586
| 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 已提交
3587

3588 3589 3590 3591
| Name | Type  | Mandatory  | Default Value | Description         |
| ---- | ------ | ---- | ---- | ------------- |
| code | number | Yes   | -    | Status code to set.|

E
ester.zhou 已提交
3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603
### 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.|

3604 3605
## FileSelectorResult<sup>9+</sup>

E
esterzhou 已提交
3606
Notifies the **\<Web>** component of the file selection result. For the sample code, see [onShowFileSelector](#onshowfileselector9).
3607 3608 3609 3610 3611 3612 3613 3614

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

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

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

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

3616 3617 3618 3619 3620 3621
| Name     | Type           | Mandatory  | Default Value | Description        |
| -------- | --------------- | ---- | ---- | ------------ |
| fileList | Array\<string\> | Yes   | -    | List of files to operate.|

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

E
esterzhou 已提交
3622
Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9).
3623

E
ester.zhou 已提交
3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635
### getTitle<sup>9+</sup>

getTitle(): string

Obtains the title of this file selector.

**Return value**

| Type    | Description      |
| ------ | -------- |
| string | Title of the file selector.|

3636 3637 3638 3639 3640 3641 3642
### getMode<sup>9+</sup>

getMode(): FileSelectorMode

Obtains the mode of the file selector.

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

3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654
| 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 已提交
3655

3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666
| Type             | Description       |
| --------------- | --------- |
| Array\<string\> | File filtering type.|

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

isCapture(): boolean

Checks whether multimedia capabilities are invoked.

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

3668 3669 3670 3671 3672 3673
| Type     | Description          |
| ------- | ------------ |
| boolean | Whether multimedia capabilities are invoked.|

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

E
esterzhou 已提交
3674
Implements the **HttpAuthHandler** object. For the sample code, see [onHttpAuthRequest](#onhttpauthrequest9).
3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695

### 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 已提交
3696

3697 3698 3699 3700 3701 3702 3703 3704
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|

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

isHttpAuthInfoSaved(): boolean

E
ester.zhou 已提交
3705
Uses the account name and password cached on the server for authentication.
3706 3707

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

3709 3710 3711 3712
| Type     | Description                       |
| ------- | ------------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|

E
ester.zhou 已提交
3713
## SslErrorHandler<sup>9+</sup>
3714

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

E
ester.zhou 已提交
3717
### handleCancel<sup>9+</sup>
3718

E
ester.zhou 已提交
3719
handleCancel(): void
3720

E
ester.zhou 已提交
3721
Cancels this request.
3722

E
ester.zhou 已提交
3723
### handleConfirm<sup>9+</sup>
3724

E
ester.zhou 已提交
3725
handleConfirm(): void
3726

E
ester.zhou 已提交
3727
Continues using the SSL certificate.
E
ester.zhou 已提交
3728 3729 3730

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

E
esterzhou 已提交
3731
Implements a **ClientAuthenticationHandler** object returned by the **\<Web>** component. For the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9).
E
ester.zhou 已提交
3732 3733 3734 3735 3736

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

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

E
ester.zhou 已提交
3737
Uses the specified private key and client certificate chain.
E
ester.zhou 已提交
3738 3739 3740

**Parameters**

E
ester.zhou 已提交
3741 3742 3743 3744
| 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 已提交
3745

E
ester.zhou 已提交
3746 3747 3748 3749
### confirm<sup>10+</sup>

confirm(authUri : string): void

E
ester.zhou 已提交
3750 3751
**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER

E
ester.zhou 已提交
3752 3753 3754 3755 3756 3757 3758 3759
Instructs the **\<Web>** component to use the specified credentials (obtained from the certificate management module).

**Parameters**

| Name  | Type | Mandatory | Description |
| ------- | ------ | ----  | ------------- |
| authUri | string | Yes   | Key value of the credentials. |

E
ester.zhou 已提交
3760 3761 3762 3763
### cancel<sup>9+</sup>

cancel(): void

E
ester.zhou 已提交
3764
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 已提交
3765 3766 3767 3768 3769

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

ignore(): void

E
ester.zhou 已提交
3770
Ignores this request.
E
ester.zhou 已提交
3771 3772 3773

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

E
esterzhou 已提交
3774
Implements the **PermissionRequest** object. For the sample code, see [onPermissionRequest](#onpermissionrequest9).
E
ester.zhou 已提交
3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786

### 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.
3787 3788 3789

**Return value**

E
ester.zhou 已提交
3790 3791 3792
| Type    | Description          |
| ------ | ------------ |
| string | Origin of the web page that requests the permission.|
3793 3794 3795 3796 3797 3798 3799 3800 3801

### 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 已提交
3802 3803
| Type             | Description           |
| --------------- | ------------- |
3804 3805 3806 3807 3808 3809 3810 3811 3812 3813
| 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 已提交
3814 3815
| Name      | Type           | Mandatory  | Default Value | Description         |
| --------- | --------------- | ---- | ---- | ------------- |
E
ester.zhou 已提交
3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851
| 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 已提交
3852

E
ester.zhou 已提交
3853 3854
## WebContextMenuParam<sup>9+</sup>

E
ester.zhou 已提交
3855
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 已提交
3856 3857 3858 3859 3860

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

x(): number

E
ester.zhou 已提交
3861
Obtains the X coordinate of the context menu.
E
ester.zhou 已提交
3862 3863 3864

**Return value**

E
ester.zhou 已提交
3865 3866
| Type    | Description                |
| ------ | ------------------ |
E
ester.zhou 已提交
3867 3868 3869 3870 3871 3872
| 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 已提交
3873
Obtains the Y coordinate of the context menu.
E
ester.zhou 已提交
3874 3875 3876

**Return value**

E
ester.zhou 已提交
3877 3878
| Type    | Description                |
| ------ | ------------------ |
E
ester.zhou 已提交
3879 3880 3881 3882 3883 3884 3885 3886 3887 3888
| 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 已提交
3889 3890
| Type    | Description                       |
| ------ | ------------------------- |
E
ester.zhou 已提交
3891
| string | If it is a link that is being long pressed, the URL that has passed the security check is returned.|
E
ester.zhou 已提交
3892

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

E
esterzhou 已提交
3895
getUnfilteredLinkUrl(): string
E
ester.zhou 已提交
3896 3897 3898 3899 3900

Obtains the URL of the destination link.

**Return value**

E
ester.zhou 已提交
3901 3902
| Type    | Description                   |
| ------ | --------------------- |
E
ester.zhou 已提交
3903
| string | If it is a link that is being long pressed, the original URL is returned.|
E
ester.zhou 已提交
3904 3905 3906 3907 3908 3909 3910 3911 3912

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

getSourceUrl(): string

Obtain the source URL.

**Return value**

E
ester.zhou 已提交
3913 3914
| Type    | Description                      |
| ------ | ------------------------ |
E
ester.zhou 已提交
3915 3916 3917 3918 3919 3920 3921 3922 3923 3924
| 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 已提交
3925 3926
| Type     | Description                       |
| ------- | ------------------------- |
E
ester.zhou 已提交
3927 3928
| boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.|

E
ester.zhou 已提交
3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000
### 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 已提交
4001 4002
## WebContextMenuResult<sup>9+</sup>

E
ester.zhou 已提交
4003
Implements a **WebContextMenuResult** object. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
E
ester.zhou 已提交
4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016

### 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 已提交
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040
### 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 已提交
4041 4042
## JsGeolocation

E
esterzhou 已提交
4043
Implements the **PermissionRequest** object. For the sample code, see [onGeolocationShow Event](#ongeolocationshow).
E
ester.zhou 已提交
4044 4045 4046 4047 4048 4049 4050 4051 4052

### invoke

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

Sets the geolocation permission status of a web page.

**Parameters**

E
ester.zhou 已提交
4053 4054 4055 4056
| Name   | Type   | Mandatory  | Default Value | Description                                    |
| ------ | ------- | ---- | ---- | ---------------------------------------- |
| origin | string  | Yes   | -    | Index of the origin.                              |
| allow  | boolean | Yes   | -    | Geolocation permission status.                            |
E
ester.zhou 已提交
4057
| 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 已提交
4058

E
ester.zhou 已提交
4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141
## MessageLevel

| Name   | Description   |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info  | Information level.|
| Log   | Log level.|
| Warn  | Warning level. |

## RenderExitReason

Enumerates the reasons why the rendering process exits.

| 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.            |

## MixedMode

| 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.              |

## 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.                       |

## 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.   |

 ## HitTestType

| 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.                   |

## SslError<sup>9+</sup>

Enumerates the error codes returned by **onSslErrorEventReceive** API.

| 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.|

## ProtectedResourceType<sup>9+</sup>

| Name       | Description           | Remarks                        |
| --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|

## WebDarkMode<sup>9+</sup>
| Name     | Description                                  |
| ------- | ------------------------------------ |
| 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 已提交
4142 4143 4144 4145 4146 4147 4148 4149 4150
## WebMediaOptions<sup>10+</sup>

Describes the web-based media playback policy.

| Name          | Type      | Readable| Writable| Mandatory| Description                        |
| -------------- | --------- | ---- | ---- | --- | ---------------------------- |
| resumeInterval |  number   |  Yes | Yes  |  No |Validity period for automatically resuming a paused web audio, in seconds. The maximum validity period is 60 seconds.|
| audioExclusive |  boolean  |  Yes | Yes  |  No | Whether the audio of multiple **\<Web>** instances in an application is exclusive.   |

E
ester.zhou 已提交
4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209
## DataResubmissionHandler<sup>9+</sup>

Implements the **DataResubmissionHandler** object for resubmitting or canceling the web form data.

### 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();
        })
      }
    }
  }
  ```

  ## WebController
E
ester.zhou 已提交
4210

E
esterzhou 已提交
4211
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 已提交
4212

E
ester.zhou 已提交
4213 4214
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 已提交
4215 4216 4217 4218 4219 4220
### Creating an Object

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

E
ester.zhou 已提交
4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253
### getCookieManager<sup>9+</sup>

getCookieManager(): WebCookie

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

**Return value**

| Type       | Description                                      |
| --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).|

**Example**

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

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

E
ester.zhou 已提交
4254
### requestFocus<sup>(deprecated)</sup>
4255 4256 4257 4258 4259

requestFocus()

Requests focus for this web page.

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

4262
**Example**
E
ester.zhou 已提交
4263

4264 4265 4266 4267 4268
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4269
    controller: WebController = new WebController()
E
ester.zhou 已提交
4270

4271 4272 4273 4274
    build() {
      Column() {
        Button('requestFocus')
          .onClick(() => {
E
ester.zhou 已提交
4275
            this.controller.requestFocus()
4276 4277 4278 4279 4280 4281 4282
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4283
### accessBackward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4284 4285 4286 4287 4288

accessBackward(): boolean

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

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

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

4293 4294 4295 4296 4297
| 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 已提交
4298

4299 4300 4301 4302 4303
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4304
    controller: WebController = new WebController()
E
ester.zhou 已提交
4305

4306 4307 4308 4309
    build() {
      Column() {
        Button('accessBackward')
          .onClick(() => {
E
ester.zhou 已提交
4310 4311
            let result = this.controller.accessBackward()
            console.log('result:' + result)
4312 4313 4314 4315 4316 4317 4318
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4319
### accessForward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4320 4321 4322 4323 4324

accessForward(): boolean

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

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

4327
**Return value**
E
ester.zhou 已提交
4328

4329 4330 4331 4332 4333
| 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 已提交
4334

4335 4336 4337 4338 4339
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4340
    controller: WebController = new WebController()
E
ester.zhou 已提交
4341

4342 4343 4344 4345
    build() {
      Column() {
        Button('accessForward')
          .onClick(() => {
E
ester.zhou 已提交
4346 4347
            let result = this.controller.accessForward()
            console.log('result:' + result)
4348 4349 4350 4351 4352 4353 4354
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4355
### accessStep<sup>(deprecated)</sup>
E
ester.zhou 已提交
4356 4357 4358

accessStep(step: number): boolean

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

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

4363 4364 4365 4366
**Parameters**

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

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

4371 4372
| Type     | Description       |
| ------- | --------- |
E
ester.zhou 已提交
4373
| boolean | Whether going forward or backward from the current page is successful.|
4374 4375

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

4377 4378 4379 4380 4381
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4382 4383
    controller: WebController = new WebController()
    @State steps: number = 2
E
ester.zhou 已提交
4384

4385 4386 4387 4388
    build() {
      Column() {
        Button('accessStep')
          .onClick(() => {
E
ester.zhou 已提交
4389 4390
            let result = this.controller.accessStep(this.steps)
            console.log('result:' + result)
4391 4392 4393 4394 4395 4396
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4397

E
ester.zhou 已提交
4398
### backward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4399 4400 4401 4402 4403

backward(): void

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

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

4406
**Example**
E
ester.zhou 已提交
4407

4408 4409 4410 4411 4412
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4413
    controller: WebController = new WebController()
E
ester.zhou 已提交
4414

4415 4416 4417 4418
    build() {
      Column() {
        Button('backward')
          .onClick(() => {
E
ester.zhou 已提交
4419
            this.controller.backward()
4420 4421 4422 4423 4424 4425
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4426

E
ester.zhou 已提交
4427
### forward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4428 4429 4430 4431 4432

forward(): void

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

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

4435
**Example**
E
ester.zhou 已提交
4436

4437 4438 4439 4440 4441
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4442
    controller: WebController = new WebController()
E
ester.zhou 已提交
4443

4444 4445 4446 4447
    build() {
      Column() {
        Button('forward')
          .onClick(() => {
E
ester.zhou 已提交
4448
            this.controller.forward()
4449 4450 4451 4452 4453 4454 4455
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4456
### deleteJavaScriptRegister<sup>(deprecated)</sup>
4457 4458 4459 4460 4461

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 已提交
4462 4463
This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](../apis/js-apis-webview.md#deletejavascriptregister).

4464
**Parameters**
E
ester.zhou 已提交
4465

4466 4467 4468 4469 4470
| 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 已提交
4471

4472 4473 4474 4475 4476
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4477 4478
    controller: WebController = new WebController()
    @State name: string = 'Object'
E
ester.zhou 已提交
4479

4480 4481 4482 4483
    build() {
      Column() {
        Button('deleteJavaScriptRegister')
          .onClick(() => {
E
ester.zhou 已提交
4484
            this.controller.deleteJavaScriptRegister(this.name)
4485 4486 4487 4488 4489 4490 4491
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4492
### getHitTest<sup>(deprecated)</sup>
E
ester.zhou 已提交
4493 4494 4495

getHitTest(): HitTestType

E
ester.zhou 已提交
4496
Obtains the element type of the area being clicked.
E
ester.zhou 已提交
4497

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

4500
**Return value**
E
ester.zhou 已提交
4501

4502 4503 4504 4505 4506
| Type                             | Description         |
| ------------------------------- | ----------- |
| [HitTestType](#hittesttype)| Element type of the area being clicked.|

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

4508 4509 4510 4511 4512
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4513
    controller: WebController = new WebController()
E
ester.zhou 已提交
4514

4515 4516 4517 4518
    build() {
      Column() {
        Button('getHitTest')
          .onClick(() => {
E
ester.zhou 已提交
4519 4520
            let hitType = this.controller.getHitTest()
            console.log("hitType: " + hitType)
4521 4522 4523 4524 4525 4526 4527
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

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

4530
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
E
ester.zhou 已提交
4531 4532 4533

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

E
ester.zhou 已提交
4534
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 已提交
4535

E
ester.zhou 已提交
4536
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 已提交
4537

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

4540
**Parameters**
E
ester.zhou 已提交
4541

4542 4543 4544 4545 4546 4547 4548 4549 4550
| 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 已提交
4551

4552 4553 4554 4555 4556
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4557
    controller: WebController = new WebController()
E
ester.zhou 已提交
4558

4559 4560 4561 4562 4563 4564 4565 4566
    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 已提交
4567
            })
4568 4569 4570 4571 4572 4573
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4574

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

4577
loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
E
ester.zhou 已提交
4578 4579 4580 4581 4582

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**.

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

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

4587
**Parameters**
E
ester.zhou 已提交
4588

4589 4590 4591 4592 4593 4594
| 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 已提交
4595

4596 4597 4598 4599 4600
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4601
    controller: WebController = new WebController()
E
ester.zhou 已提交
4602

4603 4604 4605 4606
    build() {
      Column() {
        Button('loadUrl')
          .onClick(() => {
E
ester.zhou 已提交
4607
            this.controller.loadUrl({ url: 'www.example.com' })
4608 4609 4610 4611 4612 4613
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4614

E
ester.zhou 已提交
4615
### onActive<sup>(deprecated)</sup>
E
ester.zhou 已提交
4616 4617 4618

onActive(): void

E
ester.zhou 已提交
4619
Called when the **\<Web>** component enters the active state.
E
ester.zhou 已提交
4620

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

4623
**Example**
E
ester.zhou 已提交
4624

4625 4626 4627 4628 4629
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4630
    controller: WebController = new WebController()
E
ester.zhou 已提交
4631

4632 4633 4634 4635
    build() {
      Column() {
        Button('onActive')
          .onClick(() => {
E
ester.zhou 已提交
4636
            this.controller.onActive()
4637 4638 4639 4640 4641 4642 4643
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4644
### onInactive<sup>(deprecated)</sup>
E
ester.zhou 已提交
4645 4646 4647

onInactive(): void

E
ester.zhou 已提交
4648
Called when the **\<Web>** component enters the inactive state.
E
ester.zhou 已提交
4649

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

4652
**Example**
E
ester.zhou 已提交
4653

4654 4655 4656 4657 4658
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4659
    controller: WebController = new WebController()
E
ester.zhou 已提交
4660

4661 4662 4663 4664
    build() {
      Column() {
        Button('onInactive')
          .onClick(() => {
E
ester.zhou 已提交
4665
            this.controller.onInactive()
4666 4667 4668 4669 4670 4671 4672
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4673
### zoom<sup>(deprecated)</sup>
4674 4675 4676 4677
zoom(factor: number): void

Sets a zoom factor for the current web page.

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

4680
**Parameters**
E
ester.zhou 已提交
4681

4682 4683 4684 4685 4686
| 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 已提交
4687

4688 4689 4690 4691 4692
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4693 4694
    controller: WebController = new WebController()
    @State factor: number = 1
E
ester.zhou 已提交
4695

4696 4697 4698 4699
    build() {
      Column() {
        Button('zoom')
          .onClick(() => {
E
ester.zhou 已提交
4700
            this.controller.zoom(this.factor)
4701 4702 4703 4704 4705 4706 4707
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

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

4710
refresh()
E
ester.zhou 已提交
4711

E
ester.zhou 已提交
4712
Called when the **\<Web>** component refreshes the web page.
E
ester.zhou 已提交
4713

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

4716
**Example**
E
ester.zhou 已提交
4717

4718 4719 4720 4721 4722
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4723
    controller: WebController = new WebController()
E
ester.zhou 已提交
4724

4725 4726 4727 4728
    build() {
      Column() {
        Button('refresh')
          .onClick(() => {
E
ester.zhou 已提交
4729
            this.controller.refresh()
4730 4731 4732 4733 4734 4735
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4736

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

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

E
ester.zhou 已提交
4741 4742 4743
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).
4744 4745

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

4747 4748
| Name       | Type           | Mandatory  | Default Value | Description                                    |
| ---------- | --------------- | ---- | ---- | ---------------------------------------- |
E
ester.zhou 已提交
4749
| 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.|
4750 4751 4752 4753
| 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 已提交
4754

4755 4756 4757 4758 4759 4760 4761 4762
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct Index {
    controller: WebController = new WebController()
    testObj = {
      test: (data) => {
E
ester.zhou 已提交
4763
        return "ArkUI Web Component"
4764 4765
      },
      toString: () => {
E
ester.zhou 已提交
4766
        console.log('Web Component toString')
4767 4768 4769 4770 4771 4772 4773 4774 4775 4776
      }
    }
    build() {
      Column() {
        Row() {
          Button('Register JavaScript To Window').onClick(() => {
            this.controller.registerJavaScriptProxy({
              object: this.testObj,
              name: "objName",
              methodList: ["test", "toString"],
E
ester.zhou 已提交
4777
            })
4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796
          })
        }
        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 已提交
4797 4798
          str = objName.test("test function")
          console.log('objName.test result:'+ str)
4799 4800 4801
      }
  </script>
  </html>
E
ester.zhou 已提交
4802

4803
  ```
E
ester.zhou 已提交
4804

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

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

E
ester.zhou 已提交
4809
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 已提交
4810

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

4813
**Parameters**
E
ester.zhou 已提交
4814

4815 4816 4817 4818 4819 4820
| 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 已提交
4821

4822 4823 4824 4825 4826
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4827
    controller: WebController = new WebController()
4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839
    @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 已提交
4840 4841
            }})
          console.info('url: ', e.url)
4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857
        })
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
    <meta charset="utf-8">
    <body>
        Hello world!
    </body>
    <script type="text/javascript">
    function test() {
E
ester.zhou 已提交
4858
        console.log('Ark WebComponent')
4859 4860 4861 4862
        return "This value is from index.html"
    }
    </script>
  </html>
E
ester.zhou 已提交
4863

4864
  ```
E
ester.zhou 已提交
4865

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

4868
stop()
E
ester.zhou 已提交
4869 4870 4871

Stops page loading.

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

4874
**Example**
E
ester.zhou 已提交
4875

4876 4877 4878 4879 4880
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4881
    controller: WebController = new WebController()
E
ester.zhou 已提交
4882

4883 4884 4885 4886
    build() {
      Column() {
        Button('stop')
          .onClick(() => {
E
ester.zhou 已提交
4887
            this.controller.stop()
4888 4889 4890 4891 4892 4893 4894
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4895
### clearHistory<sup>(deprecated)</sup>
E
ester.zhou 已提交
4896 4897 4898 4899 4900

clearHistory(): void

Clears the browsing history.

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

4903
**Example**
E
ester.zhou 已提交
4904

4905 4906 4907 4908 4909
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4910
    controller: WebController = new WebController()
E
ester.zhou 已提交
4911

4912 4913 4914 4915
    build() {
      Column() {
        Button('clearHistory')
          .onClick(() => {
E
ester.zhou 已提交
4916
            this.controller.clearHistory()
4917 4918 4919 4920 4921 4922 4923
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4924
## WebCookie<sup>(deprecated)</sup>
E
ester.zhou 已提交
4925

E
ester.zhou 已提交
4926
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.
E
ester.zhou 已提交
4927

E
ester.zhou 已提交
4928
### setCookie<sup>(deprecated)</sup>
E
ester.zhou 已提交
4929
setCookie(url: string, value: string): boolean
E
ester.zhou 已提交
4930

E
ester.zhou 已提交
4931
Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise.
E
ester.zhou 已提交
4932
This API is deprecated since API version 9. You are advised to use [setCookie<sup>9+</sup>](../apis/js-apis-webview.md#setcookie) instead.
E
ester.zhou 已提交
4933

E
ester.zhou 已提交
4934
**Parameters**
E
ester.zhou 已提交
4935

E
ester.zhou 已提交
4936 4937
| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
E
ester.zhou 已提交
4938
| url   | string | Yes   | -    | URL of the cookie to set. A complete URL is recommended.|
E
ester.zhou 已提交
4939
| value | string | Yes   | -    | Value of the cookie to set.        |
4940 4941

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

E
ester.zhou 已提交
4943 4944 4945
| Type     | Description           |
| ------- | ------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4946 4947

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

4949 4950 4951 4952 4953
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4954
    controller: WebController = new WebController()
E
ester.zhou 已提交
4955

4956 4957
    build() {
      Column() {
E
ester.zhou 已提交
4958
        Button('setCookie')
4959
          .onClick(() => {
E
ester.zhou 已提交
4960
            let result = this.controller.getCookieManager().setCookie("https://www.example.com", "a=b")
E
ester.zhou 已提交
4961
            console.log("result: " + result)
4962 4963 4964 4965 4966 4967
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4968 4969
### saveCookie<sup>(deprecated)</sup>
saveCookie(): boolean
4970

E
ester.zhou 已提交
4971
Saves the cookies in the memory to the drive. This API returns the result synchronously.
E
ester.zhou 已提交
4972
This API is deprecated since API version 9. You are advised to use [saveCookieAsync<sup>9+</sup>](../apis/js-apis-webview.md#savecookieasync) instead.
4973 4974 4975

**Return value**

E
ester.zhou 已提交
4976 4977 4978
| Type     | Description                  |
| ------- | -------------------- |
| boolean | Operation result.|
4979

E
ester.zhou 已提交
4980
**Example**
4981

E
ester.zhou 已提交
4982 4983 4984 4985 4986
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4987
    controller: WebController = new WebController()
E
ester.zhou 已提交
4988

E
ester.zhou 已提交
4989 4990
    build() {
      Column() {
E
ester.zhou 已提交
4991
        Button('saveCookie')
E
ester.zhou 已提交
4992
          .onClick(() => {
E
ester.zhou 已提交
4993
            let result = this.controller.getCookieManager().saveCookie()
E
ester.zhou 已提交
4994
            console.log("result: " + result)
E
ester.zhou 已提交
4995 4996 4997 4998 4999 5000
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```