ts-basic-components-web.md 136.1 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.
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

29 30
| Name       | Type                                    | Mandatory  | Description   |
| ---------- | ---------------------------------------- | ---- | ------- |
E
ester.zhou 已提交
31
| src        | [ResourceStr](ts-types.md)               | Yes   | Address of a web page resource. 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. This API 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
  import web_webview from '@ohos.web.webview'
E
ester.zhou 已提交
40

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

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

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

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

72
  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 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  let url = 'file://' + globalThis.filesDir + '/index.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 **EntryAbility.ts** file.
E
ester.zhou 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

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

E
ester.zhou 已提交
108
     HTML file to be loaded:
E
ester.zhou 已提交
109 110 111 112 113 114 115 116 117
     ```html
     <!-- index.html -->
     <!DOCTYPE html>
     <html>
         <body>
             <p>Hello World</p>
         </body>
     </html>
     ```
E
ester.zhou 已提交
118 119

## Attributes
120

121
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).
122 123 124 125 126 127 128 129

### domStorageAccess

domStorageAccess(domStorageAccess: boolean)

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

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

131 132
| Name             | Type   | Mandatory  | Default Value  | Description                                |
| ---------------- | ------- | ---- | ----- | ------------------------------------ |
133 134 135
| domStorageAccess | boolean | Yes   | false | Whether to enable the DOM Storage API.|

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

137 138
  ```ts
  // xxx.ets
E
ester.zhou 已提交
139 140
  import web_webview from '@ohos.web.webview'

141 142 143
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
144
    controller: web_webview.WebviewController = new web_webview.WebviewController()
145 146
    build() {
      Column() {
E
ester.zhou 已提交
147 148
        Web({ src: 'www.example.com', controller: this.controller })
          .domStorageAccess(true)
149 150 151 152 153 154 155 156 157
      }
    }
  }
  ```

### fileAccess

fileAccess(fileAccess: boolean)

158
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).
159 160

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

162 163
| Name       | Type   | Mandatory  | Default Value | Description                  |
| ---------- | ------- | ---- | ---- | ---------------------- |
E
ester.zhou 已提交
164
| fileAccess | boolean | Yes   | true | Whether to enable access to the file system in the application. By default, this feature is enabled.|
165 166

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

168 169
  ```ts
  // xxx.ets
E
ester.zhou 已提交
170 171
  import web_webview from '@ohos.web.webview'

172 173 174
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
175
    controller: web_webview.WebviewController = new web_webview.WebviewController()
176 177
    build() {
      Column() {
E
ester.zhou 已提交
178 179
        Web({ src: 'www.example.com', controller: this.controller })
          .fileAccess(true)
180 181 182 183 184 185 186 187 188 189 190 191
      }
    }
  }
  ```

### imageAccess

imageAccess(imageAccess: boolean)

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

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

193 194
| Name        | Type   | Mandatory  | Default Value | Description           |
| ----------- | ------- | ---- | ---- | --------------- |
195
| imageAccess | boolean | Yes   | true | Whether to enable automatic image loading.|
196 197 198 199

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

202 203 204
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
205
    controller: web_webview.WebviewController = new web_webview.WebviewController()
206 207
    build() {
      Column() {
E
ester.zhou 已提交
208 209
        Web({ src: 'www.example.com', controller: this.controller })
          .imageAccess(true)
210 211 212 213 214 215 216 217
      }
    }
  }
  ```

### javaScriptProxy

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

220
Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. The parameters cannot be updated.
221 222

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

224 225 226 227 228
| 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 已提交
229
| controller | [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes   | -    | Controller. This API is deprecated since API version 9. You are advised to use **WebviewController** instead.|
230 231

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

E
ester.zhou 已提交
233 234 235 236 237 238 239 240
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'

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

### javaScriptAccess

javaScriptAccess(javaScriptAccess: boolean)

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

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

275 276 277 278 279
| Name             | Type   | Mandatory  | Default Value | Description               |
| ---------------- | ------- | ---- | ---- | ------------------- |
| javaScriptAccess | boolean | Yes   | true | Whether JavaScript scripts can be executed.|

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

281 282
  ```ts
  // xxx.ets
E
ester.zhou 已提交
283 284
  import web_webview from '@ohos.web.webview'

285 286 287
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
288
    controller: web_webview.WebviewController = new web_webview.WebviewController()
289 290
    build() {
      Column() {
E
ester.zhou 已提交
291 292
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
293 294 295 296 297 298 299 300 301 302 303 304
      }
    }
  }
  ```

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

306 307
| Name      | Type                       | Mandatory  | Default Value           | Description     |
| --------- | --------------------------- | ---- | -------------- | --------- |
E
ester.zhou 已提交
308
| mixedMode | [MixedMode](#mixedmode)| Yes   | MixedMode.None | Mixed content to load.|
309 310

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

312 313
  ```ts
  // xxx.ets
E
ester.zhou 已提交
314 315
  import web_webview from '@ohos.web.webview'

316 317 318
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
319
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
320
    @State mode: MixedMode = MixedMode.All
321 322
    build() {
      Column() {
E
ester.zhou 已提交
323 324
        Web({ src: 'www.example.com', controller: this.controller })
          .mixedMode(this.mode)
325 326 327 328 329 330 331 332 333 334 335 336
      }
    }
  }
  ```

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

338 339 340 341 342
| 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 已提交
343

344 345
  ```ts
  // xxx.ets
E
ester.zhou 已提交
346 347
  import web_webview from '@ohos.web.webview'

348 349 350
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
351
    controller: web_webview.WebviewController = new web_webview.WebviewController()
352 353
    build() {
      Column() {
E
ester.zhou 已提交
354 355
        Web({ src: 'www.example.com', controller: this.controller })
          .onlineImageAccess(true)
356 357 358 359 360 361 362 363 364 365 366 367
      }
    }
  }
  ```

### zoomAccess

zoomAccess(zoomAccess: boolean)

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

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

369 370 371 372 373
| Name       | Type   | Mandatory  | Default Value | Description         |
| ---------- | ------- | ---- | ---- | ------------- |
| zoomAccess | boolean | Yes   | true | Whether to enable zoom gestures.|

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

375 376
  ```ts
  // xxx.ets
E
ester.zhou 已提交
377 378
  import web_webview from '@ohos.web.webview'

379 380 381
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
382
    controller: web_webview.WebviewController = new web_webview.WebviewController()
383 384
    build() {
      Column() {
E
ester.zhou 已提交
385 386
        Web({ src: 'www.example.com', controller: this.controller })
          .zoomAccess(true)
387 388 389 390 391 392 393 394 395 396 397 398
      }
    }
  }
  ```

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

400 401
| Name               | Type   | Mandatory  | Default Value | Description           |
| ------------------ | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
402
| overviewModeAccess | boolean | Yes   | true | Whether to load web pages by using the overview mode.|
403 404

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

406 407
  ```ts
  // xxx.ets
E
ester.zhou 已提交
408 409
  import web_webview from '@ohos.web.webview'

410 411 412
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
413
    controller: web_webview.WebviewController = new web_webview.WebviewController()
414 415
    build() {
      Column() {
E
ester.zhou 已提交
416 417
        Web({ src: 'www.example.com', controller: this.controller })
          .overviewModeAccess(true)
418 419 420 421 422 423 424 425 426 427 428 429
      }
    }
  }
  ```

### databaseAccess

databaseAccess(databaseAccess: boolean)

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

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

431 432
| Name           | Type   | Mandatory  | Default Value  | Description             |
| -------------- | ------- | ---- | ----- | ----------------- |
E
ester.zhou 已提交
433
| databaseAccess | boolean | Yes   | false | Whether to enable database access.|
434 435

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

437 438
  ```ts
  // xxx.ets
E
ester.zhou 已提交
439 440
  import web_webview from '@ohos.web.webview'

441 442 443
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
444
    controller: web_webview.WebviewController = new web_webview.WebviewController()
445 446
    build() {
      Column() {
E
ester.zhou 已提交
447 448
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
449 450 451 452 453 454 455 456 457 458 459 460
      }
    }
  }
  ```

### geolocationAccess

geolocationAccess(geolocationAccess: boolean)

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

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

462 463 464
| Name              | Type   | Mandatory  | Default Value | Description           |
| ----------------- | ------- | ---- | ---- | --------------- |
| geolocationAccess | boolean | Yes   | true | Whether to enable geolocation access.|
465 466

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

468 469
  ```ts
  // xxx.ets
E
ester.zhou 已提交
470 471
  import web_webview from '@ohos.web.webview'

472 473 474
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
475
    controller: web_webview.WebviewController = new web_webview.WebviewController()
476 477
    build() {
      Column() {
E
ester.zhou 已提交
478 479 480 481 482 483 484 485 486 487 488
        Web({ src: 'www.example.com', controller: this.controller })
          .geolocationAccess(true)
      }
    }
  }
  ```

### mediaPlayGestureAccess

mediaPlayGestureAccess(access: boolean)

489
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 已提交
490 491 492

**Parameters**

493 494 495
| Name   | Type   | Mandatory  | Default Value | Description             |
| ------ | ------- | ---- | ---- | ----------------- |
| access | boolean | Yes   | true | Whether video playback must be started by user gestures.|
E
ester.zhou 已提交
496 497 498 499 500

**Example**

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

E
ester.zhou 已提交
503 504 505
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
506
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
507
    @State access: boolean = true
E
ester.zhou 已提交
508 509 510 511
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .mediaPlayGestureAccess(this.access)
512 513 514 515 516
      }
    }
  }
  ```

E
ester.zhou 已提交
517 518 519 520 521
### multiWindowAccess<sup>9+</sup>

multiWindowAccess(multiWindow: boolean)

Sets whether to enable the multi-window permission.
E
ester.zhou 已提交
522
Enabling the multi-window permission requires implementation of the **onWindowNew** event. For the sample code, see [onWindowNew](#onwindownew9).
523

E
ester.zhou 已提交
524 525
**Parameters**

526 527
| Name        | Type   | Mandatory  | Default Value  | Description        |
| ----------- | ------- | ---- | ----- | ------------ |
E
ester.zhou 已提交
528 529 530 531 532 533
| multiWindow | boolean | Yes   | false | Whether to enable the multi-window permission.|

**Example**

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

E
ester.zhou 已提交
536 537 538
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
539
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
540 541 542
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
543
        .multiWindowAccess(false)
E
ester.zhou 已提交
544 545 546 547 548
      }
    }
  }
  ```

549 550 551 552
### horizontalScrollBarAccess<sup>9+</sup>

horizontalScrollBarAccess(horizontalScrollBar: boolean)

E
ester.zhou 已提交
553
Sets whether to display the horizontal scrollbar, including the default system scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed.
554 555 556 557 558 559 560 561 562 563 564

**Parameters**

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

**Example**

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

567 568 569
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
570
    controller: web_webview.WebviewController = new web_webview.WebviewController()
571 572
    build() {
      Column() {
E
ester.zhou 已提交
573
        Web({ src: $rawfile('index.html'), controller: this.controller })
574 575 576 577 578 579
        .horizontalScrollBarAccess(true)
      }
    }
  }
  ```

E
ester.zhou 已提交
580
  HTML file to be loaded:
581
  ```html
E
ester.zhou 已提交
582
  <!--index.html-->
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
  <!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 已提交
607
Sets whether to display the vertical scrollbar, including the default system scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed.
608 609 610 611 612 613 614 615 616 617 618

**Parameters**

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

**Example**

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

621 622 623
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
624
    controller: web_webview.WebviewController = new web_webview.WebviewController()
625 626
    build() {
      Column() {
E
ester.zhou 已提交
627
        Web({ src: $rawfile('index.html'), controller: this.controller })
628 629 630 631 632 633
        .verticalScrollBarAccess(true)
      }
    }
  }
  ```

E
ester.zhou 已提交
634
  HTML file to be loaded:
635
  ```html
E
ester.zhou 已提交
636
  <!--index.html-->
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
  <!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>
  ```

E
ester.zhou 已提交
657 658 659 660 661 662
### password

password(password: boolean)

Sets whether the password should be saved. This API is a void API.

663 664 665 666 667 668 669
### cacheMode

cacheMode(cacheMode: CacheMode)

Sets the cache mode.

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

671 672
| Name      | Type                       | Mandatory  | Default Value              | Description     |
| --------- | --------------------------- | ---- | ----------------- | --------- |
673 674 675
| cacheMode | [CacheMode](#cachemode)| Yes   | CacheMode.Default | Cache mode to set.|

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

677 678
  ```ts
  // xxx.ets
E
ester.zhou 已提交
679 680
  import web_webview from '@ohos.web.webview'

681 682 683
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
684
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
685
    @State mode: CacheMode = CacheMode.None
686 687
    build() {
      Column() {
E
ester.zhou 已提交
688 689
        Web({ src: 'www.example.com', controller: this.controller })
          .cacheMode(this.mode)
690 691 692 693 694
      }
    }
  }
  ```

E
ester.zhou 已提交
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
### textZoomAtio<sup>(deprecated)</sup>

textZoomAtio(textZoomAtio: number)

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

This API is deprecated since API version 9. You are advised to use [textZoomRatio<sup>9+</sup>](#textzoomratio9) instead.

**Parameters**

| Name          | Type  | Mandatory  | Default Value | Description           |
| ------------- | ------ | ---- | ---- | --------------- |
| textZoomAtio | number | Yes   | 100  | Text zoom ratio to set.|

**Example**

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

E
ester.zhou 已提交
727
### textZoomRatio<sup>9+</sup>
728 729 730 731 732 733

textZoomRatio(textZoomRatio: number)

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

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

735 736 737
| Name          | Type  | Mandatory  | Default Value | Description           |
| ------------- | ------ | ---- | ---- | --------------- |
| textZoomRatio | number | Yes   | 100  | Text zoom ratio to set.|
738 739

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

741 742
  ```ts
  // xxx.ets
E
ester.zhou 已提交
743 744
  import web_webview from '@ohos.web.webview'

745 746 747
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
748
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
749
    @State atio: number = 150
750 751
    build() {
      Column() {
E
ester.zhou 已提交
752 753
        Web({ src: 'www.example.com', controller: this.controller })
          .textZoomRatio(this.atio)
754 755 756 757 758
      }
    }
  }
  ```

E
ester.zhou 已提交
759 760 761 762 763 764 765 766
### initialScale<sup>9+</sup>

initialScale(percent: number)

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

**Parameters**

767 768 769
| Name    | Type  | Mandatory  | Default Value | Description           |
| ------- | ------ | ---- | ---- | --------------- |
| percent | number | Yes   | 100  | Scale factor of the entire page.|
E
ester.zhou 已提交
770 771 772 773 774

**Example**

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

E
ester.zhou 已提交
777 778 779
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
780
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
781 782 783 784 785 786 787 788 789 790
    @State percent: number = 100
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .initialScale(this.percent)
      }
    }
  }
  ```

791 792 793 794 795 796 797
### userAgent

userAgent(userAgent: string)

Sets the user agent.

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

799 800 801 802 803
| Name      | Type  | Mandatory  | Default Value | Description     |
| --------- | ------ | ---- | ---- | --------- |
| userAgent | string | Yes   | -    | User agent to set.|

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

805 806
  ```ts
  // xxx.ets
E
ester.zhou 已提交
807 808
  import web_webview from '@ohos.web.webview'

809 810 811
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
812
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
813
    @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'
814 815
    build() {
      Column() {
E
ester.zhou 已提交
816 817
        Web({ src: 'www.example.com', controller: this.controller })
          .userAgent(this.userAgent)
818 819 820 821
      }
    }
  }
  ```
E
ester.zhou 已提交
822

823
### blockNetwork<sup>9+</sup>
E
ester.zhou 已提交
824

825
blockNetwork(block: boolean)
E
ester.zhou 已提交
826

827
Sets whether to block online downloads.
E
ester.zhou 已提交
828

829
**Parameters**
830

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

835
**Example**
836

837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
  ```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)
      }
    }
  }
  ```
E
ester.zhou 已提交
853

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

856
defaultFixedFontSize(size: number)
E
ester.zhou 已提交
857

858 859 860 861 862 863 864
Sets the default fixed font size for the web page.

**Parameters**

| Name| Type| Mandatory| Default Value| Description                    |
| ------ | -------- | ---- | ------ | ---------------------------- |
| 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. |
865 866

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

868 869
  ```ts
  // xxx.ets
870
  import web_webview from '@ohos.web.webview'
871 872 873
  @Entry
  @Component
  struct WebComponent {
874 875
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State fontSize: number = 16
876 877
    build() {
      Column() {
E
ester.zhou 已提交
878
        Web({ src: 'www.example.com', controller: this.controller })
879
          .defaultFixedFontSize(this.fontSize)
880 881 882 883 884
      }
    }
  }
  ```

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

887
defaultFontSize(size: number)
888

889
Sets the default font size for the web page.
890 891

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

893 894 895
| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
| 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. |
896 897

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

899 900
  ```ts
  // xxx.ets
901
  import web_webview from '@ohos.web.webview'
902 903 904
  @Entry
  @Component
  struct WebComponent {
905 906
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State fontSize: number = 13
907 908 909
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
910
          .defaultFontSize(this.fontSize)
911 912 913 914 915
      }
    }
  }
  ```

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

918
minFontSize(size: number)
919

920
Sets the minimum font size for the web page.
921 922

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

924 925 926
| 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. |
927 928

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

930 931
  ```ts
  // xxx.ets
932
  import web_webview from '@ohos.web.webview'
933 934 935
  @Entry
  @Component
  struct WebComponent {
936 937
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State fontSize: number = 13
938 939 940
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
941
          .minFontSize(this.fontSize)
942 943 944 945 946
      }
    }
  }
  ```

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

949
minLogicalFontSize(size: number)
E
ester.zhou 已提交
950

951
Sets the minimum logical font size for the web page.
952

953
**Parameters**
E
ester.zhou 已提交
954

955 956 957
| Name| Type| Mandatory| Default Value| Description                |
| ------ | -------- | ---- | ------ | ------------------------ |
| 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. |
958 959

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

961 962
  ```ts
  // xxx.ets
963
  import web_webview from '@ohos.web.webview'
964 965 966
  @Entry
  @Component
  struct WebComponent {
967 968
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State fontSize: number = 13
969 970
    build() {
      Column() {
E
ester.zhou 已提交
971
        Web({ src: 'www.example.com', controller: this.controller })
972
          .minLogicalFontSize(this.fontSize)
E
ester.zhou 已提交
973
      }
974 975 976 977 978
    }
  }
  ```


979
### webFixedFont<sup>9+</sup>
980

981
webFixedFont(family: string)
E
ester.zhou 已提交
982

983
Sets the fixed font family for the web page.
984

985
**Parameters**
E
ester.zhou 已提交
986

987 988 989
| Name| Type| Mandatory| Default Value   | Description                    |
| ------ | -------- | ---- | --------- | ---------------------------- |
| family | string   | Yes  | monospace | Fixed font family to set.|
990 991

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

993 994
  ```ts
  // xxx.ets
995
  import web_webview from '@ohos.web.webview'
996 997 998
  @Entry
  @Component
  struct WebComponent {
999 1000
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "monospace"
1001 1002 1003
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1004
          .webFixedFont(this.family)
1005 1006 1007 1008 1009
      }
    }
  }
  ```

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

1012 1013 1014
webSansSerifFont(family: string)

Sets the sans serif font family for the web page.
1015 1016

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

1018 1019 1020
| Name| Type| Mandatory| Default Value    | Description                         |
| ------ | -------- | ---- | ---------- | --------------------------------- |
| family | string   | Yes  | sans-serif | Sans serif font family to set.|
1021 1022

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

1024 1025
  ```ts
  // xxx.ets
1026
  import web_webview from '@ohos.web.webview'
1027 1028 1029
  @Entry
  @Component
  struct WebComponent {
1030 1031
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "sans-serif"
1032 1033 1034
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1035
          .webSansSerifFont(this.family)
1036 1037 1038 1039 1040
      }
    }
  }
  ```

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

1043
webSerifFont(family: string)
1044

1045
Sets the serif font family for the web page.
1046 1047

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

1049 1050 1051
| Name| Type| Mandatory| Default Value| Description                    |
| ------ | -------- | ---- | ------ | ---------------------------- |
| family | string   | Yes  | serif  | Serif font family to set.|
1052 1053

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

1055 1056
  ```ts
  // xxx.ets
1057
  import web_webview from '@ohos.web.webview'
1058 1059 1060
  @Entry
  @Component
  struct WebComponent {
1061 1062
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "serif"
1063 1064 1065
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1066
          .webSerifFont(this.family)
1067 1068 1069 1070 1071
      }
    }
  }
  ```

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

1074
webStandardFont(family: string)
1075

1076
Sets the standard font family for the web page.
1077 1078

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

1080 1081 1082
| Name| Type| Mandatory| Default Value    | Description                       |
| ------ | -------- | ---- | ---------- | ------------------------------- |
| family | string   | Yes  | sans serif | Standard font family to set.|
1083 1084

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

1086 1087
  ```ts
  // xxx.ets
1088
  import web_webview from '@ohos.web.webview'
1089 1090 1091
  @Entry
  @Component
  struct WebComponent {
1092 1093
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "sans-serif"
1094 1095 1096
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1097
          .webStandardFont(this.family)
1098 1099 1100 1101 1102
      }
    }
  }
  ```

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

1105
webFantasyFont(family: string)
1106

1107
Sets the fantasy font family for the web page.
1108 1109

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

1111 1112 1113
| Name| Type| Mandatory| Default Value | Description                      |
| ------ | -------- | ---- | ------- | ------------------------------ |
| family | string   | Yes  | fantasy | Fantasy font family to set.|
1114 1115

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

1117 1118
  ```ts
  // xxx.ets
1119
  import web_webview from '@ohos.web.webview'
1120 1121 1122
  @Entry
  @Component
  struct WebComponent {
1123 1124
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "fantasy"
1125 1126 1127
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1128
          .webFantasyFont(this.family)
1129 1130 1131 1132 1133
      }
    }
  }
  ```

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

1136
webCursiveFont(family: string)
1137

1138
Sets the cursive font family for the web page.
1139 1140

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

1142 1143 1144
| Name| Type| Mandatory| Default Value | Description                      |
| ------ | -------- | ---- | ------- | ------------------------------ |
| family | string   | Yes  | cursive | Cursive font family to set.|
1145 1146

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

1148 1149
  ```ts
  // xxx.ets
1150
  import web_webview from '@ohos.web.webview'
1151 1152 1153
  @Entry
  @Component
  struct WebComponent {
1154 1155
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State family: string = "cursive"
1156 1157 1158
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1159
          .webCursiveFont(this.family)
1160 1161 1162 1163 1164
      }
    }
  }
  ```

1165
### darkMode<sup>9+</sup>
1166

1167
darkMode(mode: WebDarkMode)
1168

1169
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).
1170 1171

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

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

E
ester.zhou 已提交
1177 1178
**Example**

1179 1180
  ```ts
  // xxx.ets
1181
  import web_webview from '@ohos.web.webview'
1182 1183 1184
  @Entry
  @Component
  struct WebComponent {
1185 1186
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State mode: WebDarkMode = WebDarkMode.On
1187 1188 1189
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1190
          .darkMode(this.mode)
1191 1192 1193 1194 1195
      }
    }
  }
  ```

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

1198
forceDarkAccess(access: boolean)
1199

1200
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).
1201 1202

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

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

E
ester.zhou 已提交
1208 1209
**Example**

1210 1211
  ```ts
  // xxx.ets
1212
  import web_webview from '@ohos.web.webview'
1213 1214 1215
  @Entry
  @Component
  struct WebComponent {
1216 1217 1218
    controller: web_webview.WebviewController = new web_webview.WebviewController()
    @State mode: WebDarkMode = WebDarkMode.On
    @State access: boolean = true
1219 1220 1221
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1222 1223
          .darkMode(this.mode)
          .forceDarkAccess(this.access)
1224 1225 1226 1227 1228
      }
    }
  }
  ```

E
ester.zhou 已提交
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
### tableData

tableData(tableData: boolean)

Sets whether form data should be saved. This API is a void API.

### wideViewModeAccess

wideViewModeAccess(wideViewModeAccess: boolean)

Sets whether to support the viewport attribute of the HTML **\<meta>** tag. This API is a void API.

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

1243
pinchSmooth(isEnabled: boolean)
1244

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

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

1249 1250 1251
| Name   | Type| Mandatory| Default Value| Description                  |
| --------- | -------- | ---- | ------ | -------------------------- |
| isEnabled | boolean  | Yes  | false  | Whether to enable smooth pinch mode for the web page.|
E
ester.zhou 已提交
1252 1253

**Example**
1254 1255

  ```ts
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
// 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)
1266 1267
    }
  }
1268
}
1269 1270
  ```

E
ester.zhou 已提交
1271

1272
## Events
1273

1274
The universal events are not supported.
1275

1276 1277 1278 1279
### onAlert

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

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

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

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1294
| 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.|
1295

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

1298 1299
  ```ts
  // xxx.ets
E
ester.zhou 已提交
1300 1301
  import web_webview from '@ohos.web.webview'

1302 1303 1304
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1305
    controller: web_webview.WebviewController = new web_webview.WebviewController()
1306 1307
    build() {
      Column() {
E
ester.zhou 已提交
1308
        Web({ src: $rawfile("index.html"), controller: this.controller })
1309
          .onAlert((event) => {
E
ester.zhou 已提交
1310 1311
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
            AlertDialog.show({
              title: 'onAlert',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true
1332 1333 1334 1335 1336 1337
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1338 1339 1340
  HTML file to be loaded:
  ```html
  <!--index.html-->
E
ester.zhou 已提交
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
  <!DOCTYPE html>
  <html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
  </head>
  <body>
    <h1>WebView onAlert Demo</h1>
    <button onclick="myFunction()">Click here</button>
    <script>
      function myFunction() {
        alert("Hello World");
      }
    </script>
  </body>
  </html>
  ```

1358
### onBeforeUnload
1359

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

E
ester.zhou 已提交
1362
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.
1363 1364

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

1366 1367 1368 1369 1370
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | User operation. |
1371

E
ester.zhou 已提交
1372 1373
**Return value**

1374 1375
| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1376
| 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.|
E
ester.zhou 已提交
1377 1378 1379 1380

**Example**

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

1384 1385 1386
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1387
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1388

1389 1390
    build() {
      Column() {
E
ester.zhou 已提交
1391
        Web({ src: $rawfile("index.html"), controller: this.controller })
1392 1393 1394
          .onBeforeUnload((event) => {
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
1395
            AlertDialog.show({
1396 1397 1398 1399
              title: 'onBeforeUnload',
              message: 'text',
              primaryButton: {
                value: 'cancel',
1400
                action: () => {
1401 1402 1403 1404 1405 1406 1407
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
1408 1409 1410
                }
              },
              cancel: () => {
1411
                event.result.handleCancel()
1412 1413
              }
            })
E
ester.zhou 已提交
1414 1415 1416 1417 1418 1419 1420
            return true
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1421 1422 1423
  HTML file to be loaded:
  ```html
  <!--index.html-->
E
ester.zhou 已提交
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
  <!DOCTYPE html>
  <html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
  </head>
  <body onbeforeunload="return myFunction()">
    <h1>WebView onBeforeUnload Demo</h1>
    <a href="https://www.example.com">Click here</a>
    <script>
      function myFunction() {
        return "onBeforeUnload Event";
      }
    </script>
  </body>
  </html>
  ```

1441
### onConfirm
E
ester.zhou 已提交
1442

1443
onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
E
ester.zhou 已提交
1444

E
ester.zhou 已提交
1445
Called when **confirm()** is invoked by the web page.
E
ester.zhou 已提交
1446 1447 1448

**Parameters**

1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | User operation. |

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1459
| 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.|
E
ester.zhou 已提交
1460 1461 1462 1463 1464

**Example**

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

E
ester.zhou 已提交
1467 1468 1469
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1470
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1471

E
ester.zhou 已提交
1472 1473
    build() {
      Column() {
E
ester.zhou 已提交
1474
        Web({ src: $rawfile("index.html"), controller: this.controller })
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
          .onConfirm((event) => {
            console.log("event.url:" + event.url)
            console.log("event.message:" + event.message)
            AlertDialog.show({
              title: 'onConfirm',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true
E
ester.zhou 已提交
1498 1499 1500 1501 1502 1503
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1504 1505 1506
  HTML file to be loaded:
  ```html
  <!--index.html-->
E
ester.zhou 已提交
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
  <!DOCTYPE html>
  <html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
  </head>

  <body>
    <h1>WebView onConfirm Demo</h1>
    <button onclick="myFunction()">Click here</button>
    <p id="demo"></p>
    <script>
      function myFunction() {
        let x;
        let r = confirm("click button!");
        if (r == true) {
          x = "ok";
        } else {
          x = "cancel";
        }
        document.getElementById("demo").innerHTML = x;
      }
    </script>
  </body>
  </html>
  ```

1533
### onPrompt<sup>9+</sup>
E
ester.zhou 已提交
1534

1535
onPrompt(callback: (event?: { url: string; message: string; value: string; result: JsResult }) => boolean)
E
ester.zhou 已提交
1536 1537 1538

**Parameters**

1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | User operation. |

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
1549
| 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.|
E
ester.zhou 已提交
1550 1551 1552 1553 1554

**Example**

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

E
ester.zhou 已提交
1557 1558 1559
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1560
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1561

E
ester.zhou 已提交
1562 1563
    build() {
      Column() {
E
ester.zhou 已提交
1564
        Web({ src: $rawfile("index.html"), controller: this.controller })
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
          .onPrompt((event) => {
            console.log("url:" + event.url)
            console.log("message:" + event.message)
            console.log("value:" + event.value)
            AlertDialog.show({
              title: 'onPrompt',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
E
ester.zhou 已提交
1581
                  event.result.handlePromptConfirm(event.value)
1582 1583 1584 1585 1586 1587 1588
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true
1589 1590 1591 1592 1593 1594
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1595 1596 1597
  HTML file to be loaded:
  ```html
  <!--index.html-->
E
ester.zhou 已提交
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
  <!DOCTYPE html>
  <html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
  </head>

  <body>
    <h1>WebView onPrompt Demo</h1>
    <button onclick="myFunction()">Click here</button>
    <p id="demo"></p>
    <script>
      function myFunction() {
        let message = prompt("Message info", "Hello World");
        if (message != null && message != "") {
          document.getElementById("demo").innerHTML = message;
        }
      }
    </script>
  </body>
  </html>
  ```

1620
### onConsole
1621

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

E
ester.zhou 已提交
1624
Called to notify the host application of a JavaScript console message.
1625 1626

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

1628 1629 1630
| Name    | Type                             | Description     |
| ------- | --------------------------------- | --------- |
| message | [ConsoleMessage](#consolemessage) | Console message.|
1631 1632

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

1634 1635 1636
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the message will not be printed to the console; returns **false** otherwise.|
1637 1638 1639 1640 1641

**Example**

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

1644 1645 1646
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1647
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1648

1649 1650 1651
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1652 1653 1654 1655 1656 1657
          .onConsole((event) => {
            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
1658 1659 1660 1661 1662 1663
          })
      }
    }
  }
  ```

1664
### onDownloadStart
1665

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

E
ester.zhou 已提交
1668 1669
Instructs the main application to start downloading a file.

1670
**Parameters**
E
ester.zhou 已提交
1671

1672 1673 1674
| Name               | Type         | Description                               |
| ------------------ | ------------- | ----------------------------------- |
| url                | string        | URL for the download task.                          |
E
ester.zhou 已提交
1675
| userAgent          | string        | User agent used for download.                          |
1676 1677 1678
| 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.                        |
E
ester.zhou 已提交
1679 1680

**Example**
1681 1682 1683

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

1686 1687 1688
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1689
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1690

1691 1692
    build() {
      Column() {
E
ester.zhou 已提交
1693
        Web({ src: 'www.example.com', controller: this.controller })
1694 1695 1696 1697 1698 1699
          .onDownloadStart((event) => {
            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)
1700 1701 1702 1703 1704 1705
          })
      }
    }
  }
  ```

1706
### onErrorReceive
1707

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

E
ester.zhou 已提交
1710
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.
1711 1712

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

1714 1715 1716 1717
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
| error   | [WebResourceError](#webresourceerror)    | Encapsulation of a web page resource loading error.|
1718 1719 1720 1721 1722

**Example**

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

1725 1726 1727
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1728
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1729

1730 1731
    build() {
      Column() {
E
ester.zhou 已提交
1732
        Web({ src: 'www.example.com', controller: this.controller })
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748
          .onErrorReceive((event) => {
            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)
            for (let i of result) {
              console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue)
            }
          })
      }
    }
E
ester.zhou 已提交
1749 1750 1751
  }
  ```

1752
### onHttpErrorReceive
E
ester.zhou 已提交
1753

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

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

**Parameters**

1760 1761 1762 1763
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
| response | [WebResourceResponse](#webresourceresponse)    | Encapsulation of a resource response.|
E
ester.zhou 已提交
1764 1765 1766 1767 1768

**Example**

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

E
ester.zhou 已提交
1771 1772 1773
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1774
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1775

E
ester.zhou 已提交
1776 1777 1778
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
          .onHttpErrorReceive((event) => {
            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)
            for (let i of result) {
              console.log('The request header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
            }
            let resph = event.response.getResponseHeader()
            console.log('The response header result size is ' + resph.length)
            for (let i of resph) {
              console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
            }
E
ester.zhou 已提交
1799 1800 1801 1802 1803 1804
          })
      }
    }
  }
  ```

1805
### onPageBegin
E
ester.zhou 已提交
1806

1807
onPageBegin(callback: (event?: { url: string }) => void)
E
ester.zhou 已提交
1808

1809

E
ester.zhou 已提交
1810
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.
E
ester.zhou 已提交
1811 1812 1813

**Parameters**

1814 1815 1816 1817 1818
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

**Example**
E
ester.zhou 已提交
1819 1820 1821

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

E
ester.zhou 已提交
1824 1825 1826
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1827
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1828

E
ester.zhou 已提交
1829 1830 1831
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1832 1833
          .onPageBegin((event) => {
            console.log('url:' + event.url)
E
ester.zhou 已提交
1834 1835
          })
      }
1836 1837 1838
    }
  }
  ```
E
ester.zhou 已提交
1839

1840
### onPageEnd
1841

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

1844

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

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

1849 1850 1851
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|
1852

E
ester.zhou 已提交
1853 1854 1855 1856
**Example**

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

E
ester.zhou 已提交
1859 1860 1861
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1862
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1863

E
ester.zhou 已提交
1864 1865 1866
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1867 1868
          .onPageEnd((event) => {
            console.log('url:' + event.url)
E
ester.zhou 已提交
1869 1870 1871 1872 1873 1874
          })
      }
    }
  }
  ```

1875
### onProgressChange
E
ester.zhou 已提交
1876

1877
onProgressChange(callback: (event?: { newProgress: number }) => void)
E
ester.zhou 已提交
1878

E
ester.zhou 已提交
1879
Called when the web page loading progress changes.
E
ester.zhou 已提交
1880 1881 1882

**Parameters**

1883 1884 1885
| Name        | Type  | Description                 |
| ----------- | ------ | --------------------- |
| newProgress | number | New loading progress. The value is an integer ranging from 0 to 100.|
E
ester.zhou 已提交
1886 1887 1888 1889 1890

**Example**

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

E
ester.zhou 已提交
1893 1894 1895
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1896
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1897

E
ester.zhou 已提交
1898 1899 1900
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1901 1902 1903
          .onProgressChange((event) => {
            console.log('newProgress:' + event.newProgress)
          })
E
ester.zhou 已提交
1904 1905 1906 1907 1908
      }
    }
  }
  ```

1909
### onTitleReceive
E
ester.zhou 已提交
1910

1911
onTitleReceive(callback: (event?: { title: string }) => void)
E
ester.zhou 已提交
1912

E
ester.zhou 已提交
1913
Called when the document title of the web page is changed.
E
ester.zhou 已提交
1914 1915 1916

**Parameters**

1917 1918 1919
| Name  | Type  | Description         |
| ----- | ------ | ------------- |
| title | string | Document title.|
E
ester.zhou 已提交
1920 1921 1922 1923 1924

**Example**

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

E
ester.zhou 已提交
1927 1928 1929
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1930
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1931

E
ester.zhou 已提交
1932 1933 1934
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
1935 1936 1937
          .onTitleReceive((event) => {
            console.log('title:' + event.title)
          })
E
ester.zhou 已提交
1938 1939 1940 1941 1942
      }
    }
  }
  ```

1943
### onRefreshAccessedHistory
E
ester.zhou 已提交
1944

1945
onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean }) => void)
E
ester.zhou 已提交
1946

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

**Parameters**

1951 1952 1953
| Name        | Type   | Description                                    |
| ----------- | ------- | ---------------------------------------- |
| url         | string  | URL to be accessed.                                 |
E
ester.zhou 已提交
1954
| isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh<sup>9+</sup>](../apis/js-apis-webview.md#refresh) API, and **false** means the opposite.|
E
ester.zhou 已提交
1955 1956 1957 1958 1959

**Example**

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

E
ester.zhou 已提交
1962 1963 1964
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1965
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
1966

E
ester.zhou 已提交
1967 1968
    build() {
      Column() {
1969 1970 1971
        Web({ src: 'www.example.com', controller: this.controller })
          .onRefreshAccessedHistory((event) => {
            console.log('url:' + event.url + ' isReload:' + event.isRefreshed)
E
ester.zhou 已提交
1972 1973 1974 1975 1976 1977
          })
      }
    }
  }
  ```

E
ester.zhou 已提交
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
### onSslErrorReceive<sup>(deprecated)</sup>

onSslErrorReceive(callback: (event?: { handler: Function, error: object }) => void)

Called when an SSL error occurs during resource loading.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [onSslErrorEventReceive<sup>9+</sup>](#onsslerroreventreceive9) instead.

### onFileSelectorShow<sup>(deprecated)</sup>

onFileSelectorShow(callback: (event?: { callback: Function, fileSelector: object }) => void)

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

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [onShowFileSelector<sup>9+</sup>](#onshowfileselector9) instead.

1998
### onRenderExited<sup>9+</sup>
E
ester.zhou 已提交
1999

2000
onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)
E
ester.zhou 已提交
2001

E
ester.zhou 已提交
2002
Called when the rendering process exits abnormally.
E
ester.zhou 已提交
2003 2004 2005

**Parameters**

2006 2007 2008
| Name             | Type                                    | Description            |
| ---------------- | ---------------------------------------- | ---------------- |
| renderExitReason | [RenderExitReason](#renderexitreason)| Cause for the abnormal exit of the rendering process.|
E
ester.zhou 已提交
2009 2010 2011 2012 2013

**Example**

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

E
ester.zhou 已提交
2016 2017 2018
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2019
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2020

E
ester.zhou 已提交
2021 2022
    build() {
      Column() {
2023 2024 2025 2026
        Web({ src: 'chrome://crash/', controller: this.controller })
          .onRenderExited((event) => {
            console.log('reason:' + event.renderExitReason)
          })
E
ester.zhou 已提交
2027 2028 2029 2030 2031
      }
    }
  }
  ```

2032
### onShowFileSelector<sup>9+</sup>
E
ester.zhou 已提交
2033

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

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

**Parameters**

2040 2041 2042 2043 2044 2045 2046 2047 2048
| Name         | Type                                    | Description             |
| ------------ | ---------------------------------------- | ----------------- |
| result       | [FileSelectorResult](#fileselectorresult9) | File selection result to be sent to the **\<Web>** component.|
| fileSelector | [FileSelectorParam](#fileselectorparam9) | Information about the file selector.      |

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
E
ester.zhou 已提交
2049
| 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 已提交
2050 2051 2052 2053 2054

**Example**

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

E
ester.zhou 已提交
2057 2058 2059
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2060
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2061

E
ester.zhou 已提交
2062 2063
    build() {
      Column() {
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
        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)
              }
            })
            return true
          })
E
ester.zhou 已提交
2085 2086 2087 2088 2089
      }
    }
  }
  ```

2090
### onResourceLoad<sup>9+</sup>
E
ester.zhou 已提交
2091

2092
onResourceLoad(callback: (event: {url: string}) => void)
E
ester.zhou 已提交
2093

E
ester.zhou 已提交
2094
Called to notify the **\<Web>** component of the URL of the loaded resource file.
E
ester.zhou 已提交
2095

E
ester.zhou 已提交
2096
**Parameters**
E
ester.zhou 已提交
2097

2098 2099 2100
| Name | Type  | Description          |
| ---- | ------ | -------------- |
| url  | string | URL of the loaded resource file.|
E
ester.zhou 已提交
2101 2102 2103 2104 2105

**Example**

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

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

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

2124
### onScaleChange<sup>9+</sup>
E
ester.zhou 已提交
2125

2126
onScaleChange(callback: (event: {oldScale: number, newScale: number}) => void)
E
ester.zhou 已提交
2127

E
ester.zhou 已提交
2128
Called when the display ratio of this page changes.
E
ester.zhou 已提交
2129 2130 2131

**Parameters**

2132 2133 2134 2135
| Name     | Type  | Description        |
| -------- | ------ | ------------ |
| oldScale | number | Display ratio of the page before the change.|
| newScale | number | Display ratio of the page after the change.|
E
ester.zhou 已提交
2136 2137 2138 2139 2140

**Example**

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

E
ester.zhou 已提交
2143 2144 2145
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2146
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2147

E
ester.zhou 已提交
2148 2149
    build() {
      Column() {
2150 2151 2152 2153
        Web({ src: 'www.example.com', controller: this.controller })
          .onScaleChange((event) => {
            console.log('onScaleChange changed from ' + event.oldScale + ' to ' + event.newScale)
          })
E
ester.zhou 已提交
2154 2155 2156 2157 2158
      }
    }
  }
  ```

E
ester.zhou 已提交
2159
### onUrlLoadIntercept
E
ester.zhou 已提交
2160

2161
onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => boolean)
E
ester.zhou 已提交
2162

E
ester.zhou 已提交
2163
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 已提交
2164 2165 2166

**Parameters**

2167 2168 2169 2170 2171 2172 2173 2174 2175
| Name | Type                                    | Description     |
| ---- | ---------------------------------------- | --------- |
| data | string / [WebResourceRequest](#webresourcerequest) | URL information.|

**Return value**

| Type     | Description                      |
| ------- | ------------------------ |
| boolean | Returns **true** if the access is blocked; returns **false** otherwise.|
E
ester.zhou 已提交
2176

2177 2178 2179 2180
**Example**

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

2183 2184 2185
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2186
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2187

2188 2189
    build() {
      Column() {
2190 2191 2192 2193 2194
        Web({ src: 'www.example.com', controller: this.controller })
          .onUrlLoadIntercept((event) => {
            console.log('onUrlLoadIntercept ' + event.data.toString())
            return true
          })
E
ester.zhou 已提交
2195
      }
2196 2197 2198 2199
    }
  }
  ```

2200
### onInterceptRequest<sup>9+</sup>
E
ester.zhou 已提交
2201

2202
onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebResourceResponse)
2203

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

2206
**Parameters**
2207

2208 2209 2210
| Name    | Type                                    | Description       |
| ------- | ---------------------------------------- | ----------- |
| request | [WebResourceRequest](#webresourcerequest) | Information about the URL request.|
2211 2212

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

2214 2215 2216
| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
| [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.|
2217

2218
**Example**
2219

2220 2221
  ```ts
  // xxx.ets
E
ester.zhou 已提交
2222 2223
  import web_webview from '@ohos.web.webview'

2224 2225 2226
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2227
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
    responseweb: WebResourceResponse = new WebResourceResponse()
    heads:Header[] = new Array()
    @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() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onInterceptRequest((event) => {
            console.log('url:' + event.request.getRequestUrl())
            var head1:Header = {
              headerKey:"Connection",
              headerValue:"keep-alive"
            }
            var head2:Header = {
              headerKey:"Cache-Control",
              headerValue:"no-cache"
            }
            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
          })
      }
    }
  }
  ```
2266

2267
### onHttpAuthRequest<sup>9+</sup>
E
ester.zhou 已提交
2268

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

E
ester.zhou 已提交
2271
Called when an HTTP authentication request is received.
2272

2273
**Parameters**
2274

2275 2276 2277 2278 2279
| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
| handler | [HttpAuthHandler](#httpauthhandler9) | User operation.  |
| host    | string                               | Host to which HTTP authentication credentials apply.|
| realm   | string                               | Realm to which HTTP authentication credentials apply. |
2280 2281

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

2283 2284 2285
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|
2286

2287
**Example**
2288

2289 2290 2291 2292 2293 2294
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2295
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2296
    httpAuth: boolean = false
E
ester.zhou 已提交
2297

2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpAuthRequest((event) => {
            AlertDialog.show({
              title: 'onHttpAuthRequest',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.handler.cancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  this.httpAuth = event.handler.isHttpAuthInfoSaved()
                  if (this.httpAuth == false) {
                    web_webview.WebDataBase.saveHttpAuthCredentials(
                      event.host,
                      event.realm,
                      "2222",
                      "2222"
                    )
                    event.handler.cancel()
                  }
                }
              },
              cancel: () => {
                event.handler.cancel()
              }
            })
            return true
          })
      }
    }
  }
  ```
### onSslErrorEventReceive<sup>9+</sup>
2337

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

E
ester.zhou 已提交
2340
Called when an SSL error occurs during resource loading.
2341

2342
**Parameters**
2343

2344 2345 2346 2347
| Name    | Type                                | Description          |
| ------- | ------------------------------------ | -------------- |
| handler | [SslErrorHandler](#sslerrorhandler9) | User operation.|
| error   | [SslError](#sslerror9)          | Error code.          |
2348

2349
**Example**
2350

2351 2352 2353 2354 2355 2356
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2357
    controller: web_webview.WebviewController = new web_webview.WebviewController()
E
ester.zhou 已提交
2358

2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onSslErrorEventReceive((event) => {
            AlertDialog.show({
              title: 'onSslErrorEventReceive',
              message: 'text',
              primaryButton: {
                value: 'confirm',
                action: () => {
                  event.handler.handleConfirm()
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
                  event.handler.handleCancel()
                }
              },
              cancel: () => {
                event.handler.handleCancel()
              }
            })
            return true
          })
      }
    }
  }
  ```

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

onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array<string>, issuers : Array<string>}) => void)

E
ester.zhou 已提交
2393
Called when an SSL client certificate request is received.
2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411

**Parameters**

| Name     | Type                                    | Description           |
| -------- | ---------------------------------------- | --------------- |
| handler  | [ClientAuthenticationHandler](#clientauthenticationhandler9) | User operation. |
| host     | string                                   | Host name of the server that requests a certificate.   |
| port     | number                                   | Port number of the server that requests a certificate.   |
| keyTypes | Array<string>                            | Acceptable asymmetric private key types.   |
| issuers  | Array<string>                            | Issuer of the certificate that matches the private key.|

  **Example**
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2412
    controller: web_webview.WebviewController = new web_webview.WebviewController()
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

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onClientAuthenticationRequest((event) => {
            AlertDialog.show({
              title: 'onClientAuthenticationRequest',
              message: 'text',
              primaryButton: {
                value: 'confirm',
                action: () => {
                  event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem")
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
                  event.handler.cancel()
                }
              },
              cancel: () => {
                event.handler.ignore()
              }
            })
            return true
          })
      }
    }
  }
  ```

### onPermissionRequest<sup>9+</sup>

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

E
ester.zhou 已提交
2448
Called when a permission request is received.
2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459

**Parameters**

| Name    | Type                                    | Description          |
| ------- | ---------------------------------------- | -------------- |
| request | [PermissionRequest](#permissionrequest9) | User operation.|

**Example**

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

2462 2463 2464
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2465
    controller: web_webview.WebviewController = new web_webview.WebviewController()
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
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPermissionRequest((event) => {
            AlertDialog.show({
              title: 'title',
              message: 'text',
              primaryButton: {
                value: 'deny',
                action: () => {
                  event.request.deny()
                }
              },
              secondaryButton: {
                value: 'onConfirm',
                action: () => {
                  event.request.grant(event.request.getAccessibleResource())
                }
              },
              cancel: () => {
                event.request.deny()
              }
            })
          })
      }
    }
  }
  ```

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

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

E
ester.zhou 已提交
2499
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.
2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517

**Parameters**

| Name   | Type                                    | Description       |
| ------ | ---------------------------------------- | ----------- |
| param  | [WebContextMenuParam](#webcontextmenuparam9) | Parameters related to the context menu.    |
| result | [WebContextMenuResult](#webcontextmenuresult9) | Result of the context menu.|

**Return value**

| Type     | Description                      |
| ------- | ------------------------ |
| boolean | The value **true** means a custom menu, and **false** means the default menu.|

**Example**

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

2520 2521 2522
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2523
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540
    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 已提交
2541
Called when the scrollbar of the page scrolls.
2542 2543 2544 2545 2546

**Parameters**

| Name    | Type  | Description        |
| ------- | ------ | ------------ |
E
ester.zhou 已提交
2547 2548
| 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.|
2549 2550 2551 2552 2553

**Example**

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

2556 2557 2558
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2559
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575
    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 已提交
2576
Called when a request to obtain the geolocation information is received.
2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588

**Parameters**

| Name        | Type                           | Description          |
| ----------- | ------------------------------- | -------------- |
| origin      | string                          | Index of the origin.    |
| geolocation | [JsGeolocation](#jsgeolocation) | User operation.|

**Example**

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

2591 2592 2593
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2594
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
    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 已提交
2623
Called to notify the user that the request for obtaining the geolocation information received when **[onGeolocationShow](#ongeolocationshow)** is called has been canceled.
2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634

**Parameters**

| Name     | Type      | Description                |
| -------- | ---------- | -------------------- |
| callback | () => void | Callback invoked when the request for obtaining geolocation information has been canceled. |

**Example**

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

2637 2638 2639
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2640
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656
    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 已提交
2657
Called when the component enters full screen mode.
2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668

**Parameters**

| Name    | Type                                    | Description          |
| ------- | ---------------------------------------- | -------------- |
| handler | [FullScreenExitHandler](#fullscreenexithandler9) | Function handle for exiting full screen mode.|

**Example**

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

2671 2672 2673
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2674
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691
    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>

onFullScreenExit(callback: () => void)

E
ester.zhou 已提交
2692
Called when the component exits full screen mode.
2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703

**Parameters**

| Name     | Type      | Description         |
| -------- | ---------- | ------------- |
| callback | () => void | Callback invoked when the component exits full screen mode.|

**Example**

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

2706 2707 2708
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2709
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729
    handler: FullScreenExitHandler = null
    build() {
      Column() {
        Web({ src:'www.example.com', controller:this.controller })
        .onFullScreenExit(() => {
          console.log("onFullScreenExit...")
          this.handler.exitFullScreen()
        })
        .onFullScreenEnter((event) => {
          this.handler = event.handler
        })
      }
    }
  }
  ```

### onWindowNew<sup>9+</sup>

onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetUrl: string, handler: ControllerHandler}) => void)

2730 2731 2732
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.
2733 2734 2735 2736 2737 2738 2739 2740

**Parameters**

| 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 已提交
2741
| handler       | [ControllerHandler](#controllerhandler9) | **WebviewController** instance for setting the new window. |
2742 2743 2744 2745 2746 2747

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766
  
  // 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()
          })
        }
    }
  }

2767 2768 2769 2770
  @Entry
  @Component
  struct WebComponent {
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2771
    dialogController: CustomDialogController = null
2772 2773
    build() {
      Column() {
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          // MultiWindowAccess needs to be enabled.
          .multiWindowAccess(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)
          })
2792 2793 2794 2795 2796 2797 2798 2799 2800
      }
    }
  }
  ```

### onWindowExit<sup>9+</sup>

onWindowExit(callback: () => void)

2801
Called when this window is closed.
2802 2803 2804 2805 2806

**Parameters**

| Name     | Type      | Description        |
| -------- | ---------- | ------------ |
2807
| callback | () => void | Callback invoked when the window is closed.|
2808 2809 2810 2811 2812

**Example**

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

2815 2816 2817
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2818
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833
    build() {
      Column() {
        Web({ src:'www.example.com', controller: this.controller })
        .onWindowExit(() => {
          console.log("onWindowExit...")
        })
      }
    }
  }
  ```

### onSearchResultReceive<sup>9+</sup>

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

E
ester.zhou 已提交
2834
Called to notify the caller of the search result on the web page.
2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847

**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 已提交
2848 2849
  import web_webview from '@ohos.web.webview'

2850 2851 2852
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2853
    controller: web_webview.WebviewController = new web_webview.WebviewController()
2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870

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

### onDataResubmitted<sup>9+</sup>

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

E
ester.zhou 已提交
2871
Called when the web form data is resubmitted.
2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903

**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 已提交
2904
Called when the old page is not displayed and the new page is about to be visible.
2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935

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

2936
Called when the key event is intercepted and before it is consumed by the webview.
2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947

**Parameters**

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

**Return value**

| Type   | Description                                                        |
| ------- | ------------------------------------------------------------ |
2948
| boolean | Whether to continue to transfer the key event to the webview kernel.|
2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962

**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 已提交
2963
          if (event.keyCode == 2017 || event.keyCode == 2018) {
2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977
            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 已提交
2978
Called when an apple-touch-icon URL is received.
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 3004 3005 3006 3007 3008 3009 3010

**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 已提交
3011
Called when this web page receives a new favicon.
3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033

**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) => {
E
ester.zhou 已提交
3034
          console.log('onFaviconReceived');
3035 3036 3037 3038 3039 3040 3041
          this.icon = event.favicon;
        })
      }
    }
  }
  ```

E
ester.zhou 已提交
3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069
### onRequestSelected

onRequestSelected(callback: () => void)

Called when the **\<Web>** component obtains the focus.

**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 })
          .onRequestSelected(() => {
            console.log('onRequestSelected')
          })
      }
    }
  }
  ```

3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 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 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123
## ConsoleMessage

Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole).

### getLineNumber

getLineNumber(): number

Obtains the number of rows in this console message.

**Return value**

| Type    | Description                  |
| ------ | -------------------- |
| number | Number of rows in the console message.|

### getMessage

getMessage(): string

Obtains the log information of this console message.

**Return value**

| Type    | Description                    |
| ------ | ---------------------- |
| string | Log information of the console message.|

### getMessageLevel

getMessageLevel(): MessageLevel

Obtains the level of this console message.

**Return value**

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

| Type    | Description           |
| ------ | ------------- |
| string | Path and name of the web page source file.|

## JsResult

E
ester.zhou 已提交
3124
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).
3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138

### 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>
3139 3140 3141 3142 3143 3144

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 已提交
3145

3146 3147 3148 3149
| Name   | Type  | Mandatory  | Default Value | Description       |
| ------ | ------ | ---- | ---- | ----------- |
| result | string | Yes   | -    | User input in the dialog box.|

E
ester.zhou 已提交
3150 3151
## FullScreenExitHandler<sup>9+</sup>

3152
Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9).
E
ester.zhou 已提交
3153 3154 3155 3156 3157 3158 3159 3160 3161

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

exitFullScreen(): void

Exits full screen mode.

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

3162
Implements a **WebviewController** object for new **\<Web>** components. For the sample code, see [onWindowNew](#onwindownew9).
E
ester.zhou 已提交
3163 3164 3165

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

3166
setWebController(controller: WebviewController): void
E
ester.zhou 已提交
3167

3168
Sets a **WebviewController** object. If opening a new window is not needed, set the parameter to **null**.
E
ester.zhou 已提交
3169 3170 3171

**Parameters**

3172 3173
| Name       | Type         | Mandatory  | Default Value | Description                     |
| ---------- | ------------- | ---- | ---- | ------------------------- |
3174
| 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 已提交
3175

3176 3177
## WebResourceError

3178
Implements the **WebResourceError** object. For the sample code, see [onErrorReceive](#onerrorreceive).
3179 3180 3181 3182 3183 3184 3185 3186

### getErrorCode

getErrorCode(): number

Obtains the error code for resource loading.

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

3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198
| Type    | Description         |
| ------ | ----------- |
| number | Error code for resource loading.|

### getErrorInfo

getErrorInfo(): string

Obtains error information about resource loading.

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

3200 3201 3202 3203 3204 3205
| Type    | Description          |
| ------ | ------------ |
| string | Error information about resource loading.|

## WebResourceRequest

3206
Implements the **WebResourceRequest** object. For the sample code, see [onErrorReceive](#onerrorreceive).
3207 3208 3209 3210 3211 3212 3213 3214

### getRequestHeader

getResponseHeader() : Array\<Header\>

Obtains the information about the resource request header.

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

3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226
| 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 已提交
3227

3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238
| 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 已提交
3239

3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250
| 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 已提交
3251

3252 3253
| Type     | Description              |
| ------- | ---------------- |
E
ester.zhou 已提交
3254
| boolean | Whether the resource request is redirected by the server.|
3255 3256 3257 3258 3259 3260 3261 3262

### isRequestGesture

isRequestGesture(): boolean

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

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

3264 3265
| Type     | Description                  |
| ------- | -------------------- |
E
ester.zhou 已提交
3266
| boolean | Whether the resource request is associated with a gesture (for example, a tap).|
3267

3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279
### getRequestMethod<sup>9+</sup>

getRequestMethod(): string

Obtains the request method.

**Return value**

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

3280
## Header
E
ester.zhou 已提交
3281

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

3284 3285 3286 3287
| Name         | Type    | Description           |
| ----------- | ------ | ------------- |
| headerKey   | string | Key of the request/response header.  |
| headerValue | string | Value of the request/response header.|
E
ester.zhou 已提交
3288 3289


3290
## WebResourceResponse
E
ester.zhou 已提交
3291

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

3294
### getReasonMessage
E
ester.zhou 已提交
3295

3296
getReasonMessage(): string
E
ester.zhou 已提交
3297

3298
Obtains the status code description of the resource response.
E
ester.zhou 已提交
3299

3300
**Return value**
E
ester.zhou 已提交
3301

3302 3303 3304
| Type    | Description           |
| ------ | ------------- |
| string | Status code description of the resource response.|
E
ester.zhou 已提交
3305

3306
### getResponseCode
E
ester.zhou 已提交
3307

3308
getResponseCode(): number
E
ester.zhou 已提交
3309

3310
Obtains the status code of the resource response.
E
ester.zhou 已提交
3311

3312
**Return value**
E
ester.zhou 已提交
3313

3314 3315 3316
| Type    | Description         |
| ------ | ----------- |
| number | Status code of the resource response.|
E
ester.zhou 已提交
3317

3318
### getResponseData
E
ester.zhou 已提交
3319

3320
getResponseData(): string
E
ester.zhou 已提交
3321

3322
Obtains the data in the resource response.
E
ester.zhou 已提交
3323

3324
**Return value**
E
ester.zhou 已提交
3325

3326 3327 3328
| Type    | Description       |
| ------ | --------- |
| string | Data in the resource response.|
E
ester.zhou 已提交
3329

3330
### getResponseEncoding
E
ester.zhou 已提交
3331

3332 3333 3334 3335 3336
getResponseEncoding(): string

Obtains the encoding string of the resource response.

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

3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348
| Type    | Description        |
| ------ | ---------- |
| string | Encoding string of the resource response.|

### getResponseHeader

getResponseHeader() : Array\<Header\>

Obtains the resource response header.

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

3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360
| Type                        | Description      |
| -------------------------- | -------- |
| Array\<[Header](#header)\> | Resource response header.|

### getResponseMimeType

getResponseMimeType(): string

Obtains the MIME type of the resource response.

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

3362 3363 3364 3365 3366 3367
| Type    | Description                |
| ------ | ------------------ |
| string | MIME type of the resource response.|

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

3368
setResponseData(data: string | number)
3369 3370 3371 3372

Sets the data in the resource response.

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

3374 3375 3376
| 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.|
3377 3378 3379 3380 3381 3382 3383 3384

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

setResponseEncoding(encoding: string)

Sets the encoding string of the resource response.

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

3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396
| 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 已提交
3397

3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408
| 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 已提交
3409

3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420
| 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 已提交
3421

3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432
| 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 已提交
3433

3434 3435 3436 3437
| Name | Type  | Mandatory  | Default Value | Description         |
| ---- | ------ | ---- | ---- | ------------- |
| code | number | Yes   | -    | Status code to set.|

3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449
### 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.|

3450 3451
## FileSelectorResult<sup>9+</sup>

3452
Notifies the **\<Web>** component of the file selection result. For the sample code, see [onShowFileSelector](#onshowfileselector9).
3453 3454 3455 3456 3457 3458 3459 3460

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

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

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

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

3462 3463 3464 3465 3466 3467
| Name     | Type           | Mandatory  | Default Value | Description        |
| -------- | --------------- | ---- | ---- | ------------ |
| fileList | Array\<string\> | Yes   | -    | List of files to operate.|

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

3468
Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9).
3469

E
ester.zhou 已提交
3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481
### getTitle<sup>9+</sup>

getTitle(): string

Obtains the title of this file selector.

**Return value**

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

3482 3483 3484 3485 3486 3487 3488
### getMode<sup>9+</sup>

getMode(): FileSelectorMode

Obtains the mode of the file selector.

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

3490 3491 3492 3493 3494 3495 3496 3497 3498 3499
| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [FileSelectorMode](#fileselectormode)| Mode of the file selector.|

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

getAcceptType(): Array\<string\>

Obtains the file filtering type.

3500
**Return value**
E
ester.zhou 已提交
3501

3502 3503 3504
| Type             | Description       |
| --------------- | --------- |
| Array\<string\> | File filtering type.|
E
ester.zhou 已提交
3505

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

3508
isCapture(): boolean
3509

3510
Checks whether multimedia capabilities are invoked.
3511

3512
**Return value**
E
ester.zhou 已提交
3513

3514 3515 3516
| Type     | Description          |
| ------- | ------------ |
| boolean | Whether multimedia capabilities are invoked.|
3517

3518
## HttpAuthHandler<sup>9+</sup>
E
ester.zhou 已提交
3519

3520
Implements the **HttpAuthHandler** object. For the sample code, see [onHttpAuthRequest](#onhttpauthrequest9).
E
ester.zhou 已提交
3521

3522
### cancel<sup>9+</sup>
E
ester.zhou 已提交
3523

3524
cancel(): void
E
ester.zhou 已提交
3525

3526
Cancels HTTP authentication as requested by the user.
3527

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

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

3532
Performs HTTP authentication with the user name and password provided by the user.
E
ester.zhou 已提交
3533

3534
**Parameters**
E
ester.zhou 已提交
3535

3536 3537 3538 3539
| Name     | Type  | Mandatory  | Default Value | Description      |
| -------- | ------ | ---- | ---- | ---------- |
| userName | string | Yes   | -    | HTTP authentication user name.|
| pwd      | string | Yes   | -    | HTTP authentication password. |
E
ester.zhou 已提交
3540

3541
**Return value**
E
ester.zhou 已提交
3542

3543 3544
| Type     | Description                   |
| ------- | --------------------- |
3545
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|
3546

3547
### isHttpAuthInfoSaved<sup>9+</sup>
E
ester.zhou 已提交
3548

3549
isHttpAuthInfoSaved(): boolean
3550

E
ester.zhou 已提交
3551
Uses the account name and password cached on the server for authentication.
E
ester.zhou 已提交
3552

3553
**Return value**
E
ester.zhou 已提交
3554

3555 3556 3557
| Type     | Description                       |
| ------- | ------------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|
E
ester.zhou 已提交
3558

3559
## SslErrorHandler<sup>9+</sup>
3560

3561
Implements an **SslErrorHandler** object. For the sample code, see [onSslErrorEventReceive Event](#onsslerroreventreceive9).
3562

3563
### handleCancel<sup>9+</sup>
E
ester.zhou 已提交
3564

3565
handleCancel(): void
3566

3567
Cancels this request.
E
ester.zhou 已提交
3568

3569
### handleConfirm<sup>9+</sup>
E
ester.zhou 已提交
3570

3571
handleConfirm(): void
E
ester.zhou 已提交
3572

3573
Continues using the SSL certificate.
E
ester.zhou 已提交
3574

3575
## ClientAuthenticationHandler<sup>9+</sup>
E
ester.zhou 已提交
3576

3577
Implements a **ClientAuthenticationHandler** object returned by the **\<Web>** component. For the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9).
E
ester.zhou 已提交
3578

3579
### confirm<sup>9+</sup>
E
ester.zhou 已提交
3580

3581
confirm(priKeyFile : string, certChainFile : string): void
E
ester.zhou 已提交
3582

3583
Uses the specified private key and client certificate chain.
E
ester.zhou 已提交
3584

3585
**Parameters**
E
ester.zhou 已提交
3586

3587 3588 3589 3590
| 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 已提交
3591

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

3594
cancel(): void
3595

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

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

3600
ignore(): void
E
ester.zhou 已提交
3601

3602
Ignores this request.
3603

3604
## PermissionRequest<sup>9+</sup>
E
ester.zhou 已提交
3605

3606
Implements the **PermissionRequest** object. For the sample code, see [onPermissionRequest](#onpermissionrequest9).
3607

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

3610
deny(): void
3611

3612
Denies the permission requested by the web page.
3613

3614
### getOrigin<sup>9+</sup>
E
ester.zhou 已提交
3615

3616
getOrigin(): string
3617

3618
Obtains the origin of this web page.
E
ester.zhou 已提交
3619

3620
**Return value**
3621

3622 3623 3624
| Type    | Description          |
| ------ | ------------ |
| string | Origin of the web page that requests the permission.|
E
ester.zhou 已提交
3625

3626
### getAccessibleResource<sup>9+</sup>
E
ester.zhou 已提交
3627

3628 3629 3630
getAccessibleResource(): Array\<string\>

Obtains the list of accessible resources requested for the web page. For details about the resource types, see [ProtectedResourceType](#protectedresourcetype9).
E
ester.zhou 已提交
3631

3632
**Return value**
E
ester.zhou 已提交
3633

3634 3635 3636
| Type             | Description           |
| --------------- | ------------- |
| Array\<string\> | List of accessible resources requested by the web page.|
3637

3638
### grant<sup>9+</sup>
E
ester.zhou 已提交
3639

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

3642
Grants the permission for resources requested by the web page.
3643

3644
**Parameters**
3645

3646 3647 3648
| Name      | Type           | Mandatory  | Default Value | Description         |
| --------- | --------------- | ---- | ---- | ------------- |
| resources | Array\<string\> | Yes   | -    | List of resources that can be requested by the web page with the permission to grant.|
E
ester.zhou 已提交
3649

3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683
## 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.|
3684

3685
## WebContextMenuParam<sup>9+</sup>
E
ester.zhou 已提交
3686

3687
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).
3688

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

3691
x(): number
3692

3693
Obtains the X coordinate of the context menu.
E
ester.zhou 已提交
3694

3695
**Return value**
3696

3697 3698 3699
| Type    | Description                |
| ------ | ------------------ |
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|
E
ester.zhou 已提交
3700

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

3703
y(): number
3704

3705
Obtains the Y coordinate of the context menu.
3706 3707

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

3709 3710 3711
| Type    | Description                |
| ------ | ------------------ |
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|
3712

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

3715
getLinkUrl(): string
3716

3717
Obtains the URL of the destination link.
3718

3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729
**Return value**

| Type    | Description                       |
| ------ | ------------------------- |
| string | If it is a link that is being long pressed, the URL that has passed the security check is returned.|

### getUnfilteredLinkUrl<sup>9+</sup>

getUnfilteredLinkUrl(): string

Obtains the URL of the destination link.
3730 3731

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

3733 3734 3735
| Type    | Description                   |
| ------ | --------------------- |
| string | If it is a link that is being long pressed, the original URL is returned.|
3736

3737
### getSourceUrl<sup>9+</sup>
E
ester.zhou 已提交
3738

3739
getSourceUrl(): string
3740

3741
Obtain the source URL.
3742

3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753
**Return value**

| Type    | Description                      |
| ------ | ------------------------ |
| 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.
3754 3755

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

3757 3758 3759
| Type     | Description                       |
| ------- | ------------------------- |
| boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.|
3760

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

3763
getMediaType(): ContextMenuMediaType
E
ester.zhou 已提交
3764

3765
Obtains the media type of this web page element.
E
ester.zhou 已提交
3766

3767
**Return value**
E
ester.zhou 已提交
3768

3769 3770 3771
| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [ContextMenuMediaType](#contextmenumediatype9) | Media type of the web page element.|
E
ester.zhou 已提交
3772

3773
### getSelectionText<sup>9+</sup>
E
ester.zhou 已提交
3774

3775
getSelectionText(): string
E
ester.zhou 已提交
3776

3777
Obtains the selected text.
E
ester.zhou 已提交
3778

3779
**Return value**
3780

3781 3782 3783
| Type     | Description                       |
| ------- | ------------------------- |
| string | Selected text for the context menu. If no text is selected, null is returned.|
E
ester.zhou 已提交
3784

3785 3786 3787 3788 3789 3790 3791
### getSourceType<sup>9+</sup>

getSourceType(): ContextMenuSourceType

Obtains the event source of the context menu.

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

3793 3794 3795
| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [ContextMenuSourceType](#contextmenusourcetype9) | Event source of the context menu.|
E
ester.zhou 已提交
3796

3797
### getInputFieldType<sup>9+</sup>
E
ester.zhou 已提交
3798

3799
getInputFieldType(): ContextMenuInputFieldType
E
ester.zhou 已提交
3800

3801
Obtains the input field type of this web page element.
E
ester.zhou 已提交
3802

3803
**Return value**
3804

3805 3806 3807
| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [ContextMenuInputFieldType](#contextmenuinputfieldtype9) | Input field type.|
E
ester.zhou 已提交
3808

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

3811
isEditable(): boolean
E
ester.zhou 已提交
3812

3813
Checks whether this web page element is editable.
E
ester.zhou 已提交
3814

3815
**Return value**
E
ester.zhou 已提交
3816

3817 3818 3819
| Type     | Description                       |
| ------- | ------------------------- |
| boolean | Returns **true** if the web page element is editable; returns **false** otherwise.|
E
ester.zhou 已提交
3820

3821
### getEditStateFlags<sup>9+</sup>
E
ester.zhou 已提交
3822

3823
getEditStateFlags(): number
E
ester.zhou 已提交
3824

3825
Obtains the edit state flag of this web page element.
3826

3827
**Return value**
E
ester.zhou 已提交
3828

3829 3830 3831
| Type     | Description                       |
| ------- | ------------------------- |
| number | Edit state flag of the web page element. For details, see [ContextMenuEditStateFlags](#contextmenueditstateflags9).|
E
ester.zhou 已提交
3832

3833
## WebContextMenuResult<sup>9+</sup>
E
ester.zhou 已提交
3834

3835
Implements a **WebContextMenuResult** object. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
E
ester.zhou 已提交
3836

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

3839
closeContextMenu(): void
3840

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

3843
### copyImage<sup>9+</sup>
E
ester.zhou 已提交
3844

3845
copyImage(): void
3846

3847
Copies the image specified in **WebContextMenuParam**.
E
ester.zhou 已提交
3848

3849
### copy<sup>9+</sup>
3850

3851
copy(): void
3852

3853
Performs the copy operation related to this context menu.
3854

3855
### paste<sup>9+</sup>
E
ester.zhou 已提交
3856

3857
paste(): void
3858

3859
Performs the paste operation related to this context menu.
E
ester.zhou 已提交
3860

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

3863
cut(): void
3864

3865
Performs the cut operation related to this context menu.
3866

3867
### selectAll<sup>9+</sup>
E
ester.zhou 已提交
3868

3869
selectAll(): void
3870

3871
Performs the select all operation related to this context menu.
E
ester.zhou 已提交
3872

3873
## JsGeolocation
3874

3875
Implements the **PermissionRequest** object. For the sample code, see [onGeolocationShow Event](#ongeolocationshow).
E
ester.zhou 已提交
3876

3877
### invoke
E
ester.zhou 已提交
3878

3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890
invoke(origin: string, allow: boolean, retain: boolean): void

Sets the geolocation permission status of a web page.

**Parameters**

| Name   | Type   | Mandatory  | Default Value | Description                                    |
| ------ | ------- | ---- | ---- | ---------------------------------------- |
| origin | string  | Yes   | -    | Index of the origin.                              |
| allow  | boolean | Yes   | -    | Geolocation permission status.                            |
| 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 已提交
3891
## MessageLevel
3892

E
ester.zhou 已提交
3893 3894 3895 3896 3897 3898 3899
| Name   | Description   |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info  | Information level.|
| Log   | Log level.|
| Warn  | Warning level. |
3900

E
ester.zhou 已提交
3901
## RenderExitReason
3902

E
ester.zhou 已提交
3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 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 4001 4002 4003 4004
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.                |

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

E
ester.zhou 已提交
4005
### cancel<sup>9+</sup>
E
ester.zhou 已提交
4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035

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

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 已提交
4036
This API is deprecated since API version 9. You are advised to use [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) instead.
E
ester.zhou 已提交
4037 4038

### Creating an Object
4039 4040 4041 4042 4043

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

E
ester.zhou 已提交
4044 4045 4046 4047 4048 4049 4050 4051 4052 4053
### getCookieManager<sup>9+</sup>

getCookieManager(): WebCookie

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

**Return value**

| Type       | Description                                      |
| --------- | ---------------------------------------- |
E
ester.zhou 已提交
4054
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookiedeprecated).|
E
ester.zhou 已提交
4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076

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

4077 4078 4079 4080 4081 4082
### requestFocus<sup>(deprecated)</sup>

requestFocus()

Requests focus for this web page.

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

4085
**Example**
E
ester.zhou 已提交
4086

4087 4088 4089 4090 4091
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4092
    controller: WebController = new WebController()
E
ester.zhou 已提交
4093

4094 4095
    build() {
      Column() {
4096
        Button('requestFocus')
4097
          .onClick(() => {
4098
            this.controller.requestFocus()
4099 4100 4101 4102 4103 4104
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
4105

4106
### accessBackward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4107

4108
accessBackward(): boolean
4109

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

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

4114 4115 4116 4117 4118
**Return value**

| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if going to the previous page can be performed on the current page; returns **false** otherwise.|
4119 4120

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

4122 4123 4124 4125
  ```ts
  // xxx.ets
  @Entry
  @Component
4126
  struct WebComponent {
4127
    controller: WebController = new WebController()
E
ester.zhou 已提交
4128

4129 4130
    build() {
      Column() {
4131 4132 4133 4134
        Button('accessBackward')
          .onClick(() => {
            let result = this.controller.accessBackward()
            console.log('result:' + result)
4135
          })
4136
        Web({ src: 'www.example.com', controller: this.controller })
4137 4138 4139 4140 4141
      }
    }
  }
  ```

4142
### accessForward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4143

4144
accessForward(): boolean
E
ester.zhou 已提交
4145

4146
Checks whether going to the next page can be performed on the current page.
E
ester.zhou 已提交
4147

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

4150
**Return value**
E
ester.zhou 已提交
4151

4152 4153 4154
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if going to the next page can be performed on the current page; returns **false** otherwise.|
4155 4156

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

4158 4159 4160 4161 4162
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4163
    controller: WebController = new WebController()
E
ester.zhou 已提交
4164

4165 4166
    build() {
      Column() {
4167 4168 4169 4170 4171 4172
        Button('accessForward')
          .onClick(() => {
            let result = this.controller.accessForward()
            console.log('result:' + result)
          })
        Web({ src: 'www.example.com', controller: this.controller })
4173 4174 4175 4176 4177
      }
    }
  }
  ```

4178
### accessStep<sup>(deprecated)</sup>
E
ester.zhou 已提交
4179

4180
accessStep(step: number): boolean
E
ester.zhou 已提交
4181

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

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

4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196
**Parameters**

| Name | Type  | Mandatory  | Default Value | Description                 |
| ---- | ------ | ---- | ---- | --------------------- |
| step | number | Yes   | -    | Number of the steps to take. A positive number means to go forward, and a negative number means to go backward.|

**Return value**

| Type     | Description       |
| ------- | --------- |
| boolean | Whether going forward or backward from the current page is successful.|
E
ester.zhou 已提交
4197

4198
**Example**
E
ester.zhou 已提交
4199

4200 4201 4202 4203 4204
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4205
    controller: WebController = new WebController()
4206
    @State steps: number = 2
E
ester.zhou 已提交
4207

4208 4209
    build() {
      Column() {
4210
        Button('accessStep')
4211
          .onClick(() => {
4212 4213
            let result = this.controller.accessStep(this.steps)
            console.log('result:' + result)
4214 4215 4216 4217 4218 4219 4220
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4221
### backward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4222

4223
backward(): void
E
ester.zhou 已提交
4224

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

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

4229
**Example**
E
ester.zhou 已提交
4230

4231 4232 4233 4234 4235
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4236
    controller: WebController = new WebController()
E
ester.zhou 已提交
4237

4238 4239
    build() {
      Column() {
4240
        Button('backward')
4241
          .onClick(() => {
4242
            this.controller.backward()
4243 4244 4245 4246 4247 4248 4249
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4250
### forward<sup>(deprecated)</sup>
E
ester.zhou 已提交
4251

4252
forward(): void
E
ester.zhou 已提交
4253

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

E
ester.zhou 已提交
4256
This API is deprecated since API version 9. You are advised to use [forward<sup>9+</sup>](../apis/js-apis-webview.md#forward) instead.
E
ester.zhou 已提交
4257 4258 4259 4260 4261 4262 4263 4264

**Example**

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

E
ester.zhou 已提交
4267 4268
    build() {
      Column() {
4269
        Button('forward')
E
ester.zhou 已提交
4270
          .onClick(() => {
4271
            this.controller.forward()
E
ester.zhou 已提交
4272 4273 4274 4275 4276 4277 4278
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4279
### deleteJavaScriptRegister<sup>(deprecated)</sup>
E
ester.zhou 已提交
4280

4281
deleteJavaScriptRegister(name: string)
E
ester.zhou 已提交
4282

E
ester.zhou 已提交
4283
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](#refreshdeprecated) API.
4284

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

4287 4288 4289 4290 4291
**Parameters**

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

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

4295 4296 4297 4298 4299
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4300
    controller: WebController = new WebController()
4301
    @State name: string = 'Object'
E
ester.zhou 已提交
4302

4303 4304
    build() {
      Column() {
4305
        Button('deleteJavaScriptRegister')
4306
          .onClick(() => {
4307
            this.controller.deleteJavaScriptRegister(this.name)
4308 4309 4310 4311 4312 4313 4314
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4315
### getHitTest<sup>(deprecated)</sup>
4316

4317
getHitTest(): HitTestType
4318

E
ester.zhou 已提交
4319
Obtains the element type of the area being clicked.
4320

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

4323
**Return value**
4324

4325 4326 4327
| Type                             | Description         |
| ------------------------------- | ----------- |
| [HitTestType](#hittesttype)| Element type of the area being clicked.|
4328

E
ester.zhou 已提交
4329
**Example**
4330

E
ester.zhou 已提交
4331 4332 4333 4334 4335
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4336
    controller: WebController = new WebController()
E
ester.zhou 已提交
4337

E
ester.zhou 已提交
4338 4339
    build() {
      Column() {
4340
        Button('getHitTest')
E
ester.zhou 已提交
4341
          .onClick(() => {
4342 4343
            let hitType = this.controller.getHitTest()
            console.log("hitType: " + hitType)
E
ester.zhou 已提交
4344 4345 4346 4347 4348 4349
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
4350

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

4353
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
E
ester.zhou 已提交
4354

4355
Loads data. If **baseUrl** is empty, the specified character string will be loaded using the data protocol.
E
ester.zhou 已提交
4356

4357
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 已提交
4358

4359
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 已提交
4360

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

4363 4364 4365 4366 4367 4368 4369 4370 4371
**Parameters**

| 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.|
E
ester.zhou 已提交
4372 4373 4374 4375 4376 4377 4378 4379

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4380
    controller: WebController = new WebController()
E
ester.zhou 已提交
4381

E
ester.zhou 已提交
4382 4383
    build() {
      Column() {
4384
        Button('loadData')
E
ester.zhou 已提交
4385
          .onClick(() => {
4386 4387 4388 4389 4390
            this.controller.loadData({
              data: "<html><body bgcolor=\"white\">Source:<pre>source</pre></body></html>",
              mimeType: "text/html",
              encoding: "UTF-8"
            })
E
ester.zhou 已提交
4391 4392 4393 4394 4395 4396 4397
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

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

4400
loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
4401

4402
Loads a URL using the specified HTTP header.
E
ester.zhou 已提交
4403

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

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

E
ester.zhou 已提交
4408
This API is deprecated since API version 9. You are advised to use [loadUrl<sup>9+</sup>](../apis/js-apis-webview.md#loadurl) instead.
4409 4410 4411 4412 4413 4414 4415

**Parameters**

| Name    | Type                      | Mandatory  | Default Value | Description          |
| ------- | -------------------------- | ---- | ---- | -------------- |
| url     | string                     | Yes   | -    | URL to load.    |
| headers | Array\<[Header](#header)\> | No   | []   | Additional HTTP request header of the URL.|
E
ester.zhou 已提交
4416 4417 4418 4419 4420 4421 4422 4423

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4424
    controller: WebController = new WebController()
E
ester.zhou 已提交
4425

E
ester.zhou 已提交
4426 4427
    build() {
      Column() {
4428
        Button('loadUrl')
E
ester.zhou 已提交
4429
          .onClick(() => {
4430
            this.controller.loadUrl({ url: 'www.example.com' })
E
ester.zhou 已提交
4431 4432 4433 4434 4435 4436 4437
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4438
### onActive<sup>(deprecated)</sup>
E
ester.zhou 已提交
4439

4440
onActive(): void
E
ester.zhou 已提交
4441

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

E
ester.zhou 已提交
4444
This API is deprecated since API version 9. You are advised to use [onActive<sup>9+</sup>](../apis/js-apis-webview.md#onactive) instead.
E
ester.zhou 已提交
4445 4446 4447 4448 4449 4450 4451 4452

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4453
    controller: WebController = new WebController()
E
ester.zhou 已提交
4454

E
ester.zhou 已提交
4455 4456
    build() {
      Column() {
4457
        Button('onActive')
E
ester.zhou 已提交
4458
          .onClick(() => {
4459
            this.controller.onActive()
E
ester.zhou 已提交
4460 4461 4462 4463 4464 4465 4466
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4467
### onInactive<sup>(deprecated)</sup>
E
ester.zhou 已提交
4468

4469
onInactive(): void
E
ester.zhou 已提交
4470

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

E
ester.zhou 已提交
4473
This API is deprecated since API version 9. You are advised to use [onInactive<sup>9+</sup>](../apis/js-apis-webview.md#oninactive) instead.
E
ester.zhou 已提交
4474 4475 4476 4477 4478 4479 4480 4481

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4482
    controller: WebController = new WebController()
E
ester.zhou 已提交
4483

E
ester.zhou 已提交
4484 4485
    build() {
      Column() {
4486
        Button('onInactive')
E
ester.zhou 已提交
4487
          .onClick(() => {
4488
            this.controller.onInactive()
E
ester.zhou 已提交
4489 4490 4491 4492 4493 4494 4495
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4496 4497
### zoom<sup>(deprecated)</sup>
zoom(factor: number): void
E
ester.zhou 已提交
4498

4499
Sets a zoom factor for the current web page.
E
ester.zhou 已提交
4500

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

4503 4504 4505 4506 4507
**Parameters**

| Name   | Type  | Mandatory  | Description                          |
| ------ | ------ | ---- | ------------------------------ |
| factor | number | Yes   | Zoom factor to set. A positive value indicates zoom-in, and a negative value indicates zoom-out.|
4508 4509

**Example**
E
ester.zhou 已提交
4510 4511 4512 4513 4514 4515

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4516
    controller: WebController = new WebController()
4517
    @State factor: number = 1
E
ester.zhou 已提交
4518

E
ester.zhou 已提交
4519 4520
    build() {
      Column() {
4521
        Button('zoom')
E
ester.zhou 已提交
4522
          .onClick(() => {
4523
            this.controller.zoom(this.factor)
E
ester.zhou 已提交
4524 4525 4526 4527 4528 4529 4530
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

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

4533
refresh()
E
ester.zhou 已提交
4534

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

E
ester.zhou 已提交
4537
This API is deprecated since API version 9. You are advised to use [refresh<sup>9+</sup>](../apis/js-apis-webview.md#refresh) instead.
E
ester.zhou 已提交
4538 4539 4540 4541 4542 4543 4544 4545

**Example**

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

E
ester.zhou 已提交
4548 4549
    build() {
      Column() {
4550
        Button('refresh')
E
ester.zhou 已提交
4551
          .onClick(() => {
4552
            this.controller.refresh()
E
ester.zhou 已提交
4553 4554 4555 4556 4557 4558 4559
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

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

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

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

E
ester.zhou 已提交
4566
This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](../apis/js-apis-webview.md#registerjavascriptproxy) instead.
E
ester.zhou 已提交
4567 4568 4569

**Parameters**

4570 4571 4572 4573 4574
| Name       | Type           | Mandatory  | Default Value | Description                                    |
| ---------- | --------------- | ---- | ---- | ---------------------------------------- |
| 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.|
| 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.                |
E
ester.zhou 已提交
4575 4576 4577 4578 4579 4580 4581

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
4582
  struct Index {
E
ester.zhou 已提交
4583
    controller: WebController = new WebController()
4584 4585 4586 4587 4588 4589 4590 4591
    testObj = {
      test: (data) => {
        return "ArkUI Web Component"
      },
      toString: () => {
        console.log('Web Component toString')
      }
    }
E
ester.zhou 已提交
4592 4593
    build() {
      Column() {
4594 4595 4596 4597 4598 4599 4600
        Row() {
          Button('Register JavaScript To Window').onClick(() => {
            this.controller.registerJavaScriptProxy({
              object: this.testObj,
              name: "objName",
              methodList: ["test", "toString"],
            })
E
ester.zhou 已提交
4601
          })
4602 4603 4604
        }
        Web({ src: $rawfile('index.html'), controller: this.controller })
          .javaScriptAccess(true)
E
ester.zhou 已提交
4605 4606 4607 4608 4609
      }
    }
  }
  ```

E
ester.zhou 已提交
4610
  HTML file to be loaded:
4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625
  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
      <meta charset="utf-8">
      <body>
          Hello world!
      </body>
      <script type="text/javascript">
      function htmlTest() {
          str = objName.test("test function")
          console.log('objName.test result:'+ str)
      }
  </script>
  </html>
E
ester.zhou 已提交
4626

4627
  ```
E
ester.zhou 已提交
4628

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

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

4633 4634
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 已提交
4635
This API is deprecated since API version 9. You are advised to use [runJavaScript<sup>9+</sup>](../apis/js-apis-webview.md#runjavascript) instead.
4636 4637 4638 4639 4640 4641 4642

**Parameters**

| 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.|
E
ester.zhou 已提交
4643 4644 4645 4646 4647 4648 4649 4650

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4651
    controller: WebController = new WebController()
4652
    @State webResult: string = ''
E
ester.zhou 已提交
4653 4654
    build() {
      Column() {
4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666
        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}`)
            }})
          console.info('url: ', e.url)
        })
E
ester.zhou 已提交
4667 4668 4669 4670
      }
    }
  }
  ```
E
ester.zhou 已提交
4671
  HTML file to be loaded:
4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686
  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
    <meta charset="utf-8">
    <body>
        Hello world!
    </body>
    <script type="text/javascript">
    function test() {
        console.log('Ark WebComponent')
        return "This value is from index.html"
    }
    </script>
  </html>
E
ester.zhou 已提交
4687

4688
  ```
E
ester.zhou 已提交
4689

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

4692 4693 4694 4695
stop()

Stops page loading.

E
ester.zhou 已提交
4696
This API is deprecated since API version 9. You are advised to use [stop<sup>9+</sup>](../apis/js-apis-webview.md#stop) instead.
E
ester.zhou 已提交
4697 4698 4699 4700 4701 4702 4703 4704

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4705
    controller: WebController = new WebController()
E
ester.zhou 已提交
4706

E
ester.zhou 已提交
4707 4708
    build() {
      Column() {
4709
        Button('stop')
E
ester.zhou 已提交
4710
          .onClick(() => {
4711
            this.controller.stop()
E
ester.zhou 已提交
4712 4713 4714 4715 4716 4717 4718
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

4719
### clearHistory<sup>(deprecated)</sup>
E
ester.zhou 已提交
4720

4721
clearHistory(): void
E
ester.zhou 已提交
4722

4723
Clears the browsing history.
E
ester.zhou 已提交
4724

E
ester.zhou 已提交
4725
This API is deprecated since API version 9. You are advised to use [clearHistory<sup>9+</sup>](../apis/js-apis-webview.md#clearhistory) instead.
E
ester.zhou 已提交
4726 4727 4728 4729 4730 4731 4732 4733

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
4734
    controller: WebController = new WebController()
E
ester.zhou 已提交
4735

E
ester.zhou 已提交
4736 4737
    build() {
      Column() {
4738
        Button('clearHistory')
E
ester.zhou 已提交
4739
          .onClick(() => {
4740
            this.controller.clearHistory()
E
ester.zhou 已提交
4741 4742 4743 4744 4745 4746 4747
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

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

E
ester.zhou 已提交
4750
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.
4751

E
ester.zhou 已提交
4752
### setCookie<sup>(deprecated)</sup>
E
ester.zhou 已提交
4753
setCookie(): boolean
E
ester.zhou 已提交
4754

E
ester.zhou 已提交
4755
Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise.
4756

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

4759 4760
**Return value**

E
ester.zhou 已提交
4761 4762 4763
| Type     | Description           |
| ------- | ------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4764

E
ester.zhou 已提交
4765 4766
### saveCookie<sup>(deprecated)</sup>
saveCookie(): boolean
4767

E
ester.zhou 已提交
4768
Saves the cookies in the memory to the drive. This API returns the result synchronously.
E
ester.zhou 已提交
4769

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

E
ester.zhou 已提交
4772
**Return value**
4773

E
ester.zhou 已提交
4774 4775 4776
| Type     | Description                  |
| ------- | -------------------- |
| boolean | Operation result.|