bn.createWebview
▸ createWebview(options
): Webview
remark
supported jssdk > 3.13.0
description
Create a webview displayed above mini game.
Only one webview is supported at the same time
example
const webview = bn.createWebview({
// required, resource url, support local file path
src: '/root/src/index.html',
// position
x: 0,
y: 0,
// size
height: 500,
width: 500,
// background color in #rrggbbaa format
backgroundColor: '#FFFFFFFF'
success (res) {}
}
})
// update webview properties
webview.update({
x: 100,
y: 100,
})
// close webview
webview.close()
// send message to webview
webview.postMessage('test')
// listen event on webview
webview.onLoad(() => {})
Parameters
Name | Type | Description |
---|---|---|
options | CreateWebviewOptions | create webview options |
Returns
Webview
Webview - the webview instance
CreateWebviewOptions
Ƭ CreateWebviewOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
src | string | Src of webview page supports http:// https:// or local file path |
height? | number | Height of webview component |
width? | number | Width of webview component |
x? | number | Horizontal position of webview |
y? | number | Vertical position of webview |
backgroundColor? | string | 8 digit hex value #ffffffff |
injected? | string [] | Inject specific javascript script file before page loaded |
bounce? | boolean | whether the page bounces when scroll beyond top/bottom |
loadingBar? | boolean | whether the page shows loading bar when loading page |
webPreferences? | { [key: string] : unknown ; userAgent? : string } | Setting web preferences, currently only userAgent is supported |
webPreferences.userAgent? | string | - |
pageId? | number | Page id, used to identify the page to show webview. Required in widget. example ts const pageId = getCurrentInstance().page.getPageId(); createWebview({ ...options, pageId, }) |
success? | CreateWebviewSuccessCallback | - |
fail? | CreateWebviewCallback | - |
complete? | CreateWebviewCallback | - |
CreateWebviewSuccessCallback
Ƭ CreateWebviewSuccessCallback: ({ errMsg, webview, }
: { errMsg
: string
; webview
: IWebview
}) => void
Type declaration
▸ ({ errMsg, webview, }
): void
Parameters
Name | Type |
---|---|
`{ | |
errMsg, | |
webview, | |
}` | Object |
`{ | |
errMsg, | |
webview, | |
}.errMsg` | string |
`{ | |
errMsg, | |
webview, | |
}.webview` | IWebview |
Returns
void
Interface: IWebview
Name | Type | Description |
---|---|---|
src | string | |
x | number | |
y | number | |
backgroundColor | string | |
update | (options ): void | |
close | (): void | |
postMessage | (message ): void | |
canGoBack | (): Promise <boolean > | |
canGoForward | (): Promise <boolean > | |
url | (): Promise <string > | |
title | (): Promise <string > | |
goBack | (): Promise <void > | |
goForward | (): Promise <void > | |
refresh | (): Promise <void > | |
clearCache | (): Promise <void > | |
invoke | (method , payload? , options? ): Promise <any > | |
clearScrollStatus | (): Promise <void > | |
onMessage | (handler ): void | |
offMessage | (handler ): void | |
onLoad | (handler ): void | |
offLoad | (handler ): void | |
onError | (handler ): void | |
offError | (handler ): void |
update
▸ update(options
): void
Parameters
Name | Type |
---|---|
options | Optional <CreateWebviewOptions > |
Returns
void
close
▸ close(): void
Returns
void
postMessage
▸ postMessage(message
): void
Parameters
Name | Type |
---|---|
message | string |
Returns
void