# 属性
通用属性仅支持[aspectRatio](../apis-arkui/arkui-ts/ts-universal-attributes-layout-constraints.md#aspectratio)、[backdropBlur](../apis-arkui/arkui-ts/ts-universal-attributes-background.md#backdropblur)、[backgroundColor](../apis-arkui/arkui-ts/ts-universal-attributes-background.md#backgroundcolor)、[bindContentCover](../apis-arkui/arkui-ts/ts-universal-attributes-modal-transition.md#bindcontentcover)、[bindContextMenu](../apis-arkui/arkui-ts/ts-universal-attributes-menu.md#bindcontextmenu8)、[bindMenu ](../apis-arkui/arkui-ts/ts-universal-attributes-menu.md#bindmenu)、[bindSheet](../apis-arkui/arkui-ts/ts-universal-attributes-sheet-transition.md#bindsheet)、[borderColor](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#bordercolor)、[borderRadius](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#borderradius)、[borderStyle](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#borderstyle)、[borderWidth](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#borderwidth)、[clip](../apis-arkui/arkui-ts/ts-universal-attributes-sharp-clipping.md#clip12)、[constraintSize](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#constraintsize)、[defaultFocus](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#defaultfocus9)、[focusable](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#focusable)、[tabIndex](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#tabindex9)、[groupDefaultFocus](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#groupdefaultfocus9)、[displayPriority](../apis-arkui/arkui-ts/ts-universal-attributes-layout-constraints.md#displaypriority)、[enabled](../apis-arkui/arkui-ts/ts-universal-attributes-enable.md#enabled)、[flexBasis](../apis-arkui/arkui-ts/ts-universal-attributes-flex-layout.md#flexbasis)、[flexShrink](../apis-arkui/arkui-ts/ts-universal-attributes-flex-layout.md#flexshrink)、[layoutWeight](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#layoutweight)、[id](../apis-arkui/arkui-ts/ts-universal-attributes-component-id.md#id)、[gridOffset](../apis-arkui/arkui-ts/ts-universal-attributes-grid.md#属性)、[gridSpan](../apis-arkui/arkui-ts/ts-universal-attributes-grid.md#属性)、[useSizeType](../apis-arkui/arkui-ts/ts-universal-attributes-grid.md#属性)、[height](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#height)、[touchable](../apis-arkui/arkui-ts/ts-universal-attributes-click.md#touchabledeprecated)、[margin](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#margin)、[markAnchor](../apis-arkui/arkui-ts/ts-universal-attributes-location.md#markanchor)、[offset](../apis-arkui/arkui-ts/ts-universal-attributes-location.md#offset)、[width](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#width)、[zIndex](../apis-arkui/arkui-ts/ts-universal-attributes-z-order.md#zindex)、[visibility](../apis-arkui/arkui-ts/ts-universal-attributes-visibility.md#visibility)、[scale](../apis-arkui/arkui-ts/ts-universal-attributes-transformation.md#scale)、[translate](../apis-arkui/arkui-ts/ts-universal-attributes-transformation.md#translate)、[responseRegion](../apis-arkui/arkui-ts/ts-universal-attributes-touch-target.md#responseregion)、[size](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#size)、[opacity](../apis-arkui/arkui-ts/ts-universal-attributes-opacity.md#opacity)、[shadow](../apis-arkui/arkui-ts/ts-universal-attributes-image-effect.md#shadow)、[sharedTransition](../apis-arkui/arkui-ts/ts-transition-animation-shared-elements.md)、[transition](../apis-arkui/arkui-ts/ts-transition-animation-component.md)、[position](../apis-arkui/arkui-ts/ts-universal-attributes-location.md#position)。
> **说明:**
>
> - 该组件首批接口从API version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
>
> - 示例效果请以真机运行为准,当前DevEco Studio预览器不支持。
## domStorageAccess
domStorageAccess(domStorageAccess: boolean)
设置是否开启文档对象模型存储接口(DOM Storage API)权限,默认未开启。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------------- | ------- | ---- | ------------------------------------ |
| domStorageAccess | boolean | 是 | 设置是否开启文档对象模型存储接口(DOM Storage API)权限。
true表示开启文档对象模型存储接口权限,false表示不开启文档对象模型存储接口权限。
默认值:false。 |
> **说明:**
>
> - 网页中使用到文档对象模型存储接口(DOM Storage API),需将其设置为true,才可正常加载网页。
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.domStorageAccess(true)
}
}
}
```
## fileAccess
fileAccess(fileAccess: boolean)
设置是否开启应用中文件系统的访问。[$rawfile(filepath/filename)](../../quick-start/resource-categories-and-access.md)中的文件不受该属性影响而被限制访问。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------- | ---- | ---------------------- |
| fileAccess | boolean | 是 | 设置是否开启应用中文件系统的访问。
true表示开启应用中文件系统的访问。false表示不开启应用中文件系统的访问。
API version 11及以前:默认值:true。
API version 12及以后:默认值:false,同时,当fileAccess为false的时候,仅只读资源目录`/data/storage/el1/bundle/entry/resources/resfile`里面的资源依然可以通过file协议访问,不受fileAccess管控。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.fileAccess(true)
}
}
}
```
## imageAccess
imageAccess(imageAccess: boolean)
设置是否允许自动加载图片资源。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------- | ---- | --------------- |
| imageAccess | boolean | 是 | 设置是否允许自动加载图片资源。
true表示设置允许自动加载图片资源,false表示设置不允许自动加载图片资源。
默认值:true。
传入undefined与null时为false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.imageAccess(true)
}
}
}
```
## javaScriptProxy
javaScriptProxy(javaScriptProxy: JavaScriptProxy)
将javaScriptProxy中的ArkTS对象注册到Web组件中,该对象将使用JavaScriptProxy中指定的名称注册到网页的所有框架中,包括所有iframe,这使得JavaScript可以调用javaScriptProxy中ArkTS对象的方法。
> **说明:**
>
> javaScriptProxy接口需要和deleteJavaScriptRegister接口配合使用,防止内存泄漏。
> javaScriptProxy对象的所有参数不支持更新。
> 注册javaScriptProxy对象时,同步与异步列表请至少选择一项不为空,可同时注册两类方法。
> 此接口只支持注册一个对象,若需要注册多个对象请使用[registerJavaScriptProxy9+](./arkts-apis-webview-WebviewController.md#registerjavascriptproxy)。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------------------------- | ---- |---------------------------------------- |
| javaScriptProxy | [JavaScriptProxy](./arkts-basic-components-web-i.md#javascriptproxy12) | 是 | 参与注册的对象。只能声明方法,不能声明属性。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
import { BusinessError } from '@kit.BasicServicesKit';
class TestObj {
constructor() {
}
test(data1: string, data2: string, data3: string): string {
console.info("data1:" + data1);
console.info("data2:" + data2);
console.info("data3:" + data3);
return "AceString";
}
asyncTest(data: string): void {
console.info("async data:" + data);
}
toString(): void {
console.info('toString' + "interface instead.");
}
}
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
testObj = new TestObj();
build() {
Column() {
Button('deleteJavaScriptRegister')
.onClick(() => {
try {
this.controller.deleteJavaScriptRegister("objName");
} catch (error) {
console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
.javaScriptAccess(true)
.javaScriptProxy({
object: this.testObj,
name: "objName",
methodList: ["test", "toString"],
asyncMethodList: ["asyncTest"],
controller: this.controller,
})
}
}
}
```
## javaScriptAccess
javaScriptAccess(javaScriptAccess: boolean)
设置是否允许执行JavaScript脚本。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------------- | ------- | ---- | ------------------- |
| javaScriptAccess | boolean | 是 | 是否允许执行JavaScript脚本。
true表示允许执行JavaScript脚本,false表示不允许执行JavaScript脚本。
传入undefined或null时不允许执行JavaScript脚本。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.javaScriptAccess(true)
}
}
}
```
## overScrollMode11+
overScrollMode(mode: OverScrollMode)
设置Web过滚动模式。当过滚动模式开启时,当用户在Web根页面上滑动到边缘时,Web会通过弹性动画弹回界面,根页面上的内部页面不会触发回弹。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---- | --------------------------------------- | ---- | ------------------ |
| mode | [OverScrollMode](./arkts-basic-components-web-e.md#overscrollmode11) | 是 | 设置Web的过滚动模式为关闭或开启。
默认值:`OverScrollMode.NEVER`,表示关闭过滚动模式。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
@State mode: OverScrollMode = OverScrollMode.ALWAYS;
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.overScrollMode(this.mode)
}
}
}
```
## mixedMode
mixedMode(mixedMode: MixedMode)
设定当安全源尝试从非安全源加载资源时的行为。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | --------------------------- | ---- | --------- |
| mixedMode | [MixedMode](./arkts-basic-components-web-e.md#mixedmode) | 是 | 要设置的混合内容模式。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
@State mode: MixedMode = MixedMode.All;
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.mixedMode(this.mode)
}
}
}
```
## onlineImageAccess
onlineImageAccess(onlineImageAccess: boolean)
设置是否允许从网络加载图片资源(通过HTTP和HTTPS访问的资源)。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------------- | ------- | ---- | ---------------- |
| onlineImageAccess | boolean | 是 | 设置是否允许从网络加载图片资源。
true表示设置允许从网络加载图片资源,false表示设置不允许从网络加载图片资源。
默认值:true。
传入undefined与null时为false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.onlineImageAccess(true)
}
}
}
```
## zoomAccess
zoomAccess(zoomAccess: boolean)
设置是否支持手势进行缩放。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------- | ---- | ------------- |
| zoomAccess | boolean | 是 | 设置是否支持手势进行缩放。
true表示设置支持手势进行缩放,false表示设置不支持手势进行缩放。
默认值:true。
传入undefined与null时为false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.zoomAccess(true)
}
}
}
```
## overviewModeAccess
overviewModeAccess(overviewModeAccess: boolean)
设置是否使用概览模式加载网页,即缩小内容以适应屏幕宽度。
**系统能力:** SystemCapability.Web.Webview.Core
**设备行为差异:** 该接口在PC/2in1设备中无效果,在其他设备中可正常调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------ | ------- | ---- | --------------- |
| overviewModeAccess | boolean | 是 | 设置是否使用概览模式加载网页。
true表示设置使用概览模式加载网页,false表示设置不使用概览模式加载网页。
默认值:true。
传入undefined与null时为false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.overviewModeAccess(true)
}
}
}
```
## databaseAccess
databaseAccess(databaseAccess: boolean)
设置是否开启数据库存储API权限。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------- | ---- | ----------------- |
| databaseAccess | boolean | 是 | 设置是否开启数据库存储API权限。
true表示设置开启数据库存储API权限,false表示设置不开启数据库存储API权限。
默认值:false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
## geolocationAccess
geolocationAccess(geolocationAccess: boolean)
设置是否开启获取地理位置权限。具体使用方式参考[管理位置权限](../../web/web-geolocation-permission.md)。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------------- | ------- | ---- | --------------- |
| geolocationAccess | boolean | 是 | 设置是否开启获取地理位置权限。
true表示设置开启获取地理位置权限,false表示设置不开启获取地理位置权限。
默认值:true。
传入undefined与null时为false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.geolocationAccess(true)
}
}
}
```
## mediaPlayGestureAccess9+
mediaPlayGestureAccess(access: boolean)
设置有声视频的自动播放是否需要用户手动点击,静音视频播放不受该接口管控。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------- |
| access | boolean | 是 | 设置有声视频的自动播放是否需要用户手动点击。
true表示设置有声视频的自动播放需要用户手动点击,false表示设置有声视频的自动播放不需要用户手动点击,能自动播放。
默认值:true。
传入undefined与null时为false。 |
**示例:**
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
@State access: boolean = true;
build() {
Column() {
Web({ src: $rawfile('index.html'), controller: this.controller })
.mediaPlayGestureAccess(this.access)
}
}
}
```
加载的html文件。
```html