# Interface Documentation
# 1. Related Interfaces
Web-view components loaded in web pages can use JSSDK 1.4.21 (opens new window), JSSDK 1.4.21(ESM) (opens new window) to access Mini-Program capabilities.
Supported interfaces:
| Interface Name | Description | Min Version |
|---|---|---|
| ft.miniProgram.navigateTo | Keep current page, navigate to another page within the application | 1.0.0 |
| ft.miniProgram.navigateBack | Close current page, return to previous page or multiple pages | 1.0.0 |
| ft.miniProgram.switchTab | Navigate to tabBar page, close all other non-tabBar pages | 1.0.0 |
| ft.miniProgram.redirectTo | Close current page, navigate to another page within the application | 1.0.0 |
| ft.miniProgram.reLaunch | Close all pages, open to a page within the application | 1.0.0 |
| ft.miniProgram.postMessage | Send messages to Mini-Program, triggers component's message event at specific times | 1.0.0 |
| ft.miniProgram.getEnv | Get current environment and JSSDK version number | 1.0.0 |
| ft.miniProgram.close | Close Mini-Program | 1.0.3 |
| ft.miniProgram.navigateToMiniProgram | Navigate to another Mini-Program | 1.0.4 |
| ft.miniProgram.navigateBackMiniProgram | Return to previous Mini-Program | 1.0.4 |
| ft.miniProgram.onShow | Register callback for Mini-Program onShow event | 1.0.6 |
| ft.miniProgram.onHide | Register callback for Mini-Program onHide event | 1.0.8 |
| ft.miniProgram.onUnload | Register callback for Mini-Program onUnload event | 1.0.8 |
| ft.miniProgram.onWebviewEvent | Listen for events sent by Mini-Program, supports binding multiple functions | 1.4.1 |
| ft.miniProgram.offWebviewEvent | Remove listener for events sent by Mini-Program, cancels all bindings if no params passed | 1.4.1 |
| ft.miniProgram.sendWebviewEvent | Trigger the bindevent method bound to webview tag | 1.4.1 |
| ft.downloadFile | Download file | 1.0.0 |
| ft.getAppletInfo | Return current Mini-Program basic information | 1.0.0 |
| ft.openDocument | Open file | 1.0.0 |
| ft.chooseImage | Take photo or choose image from phone album | 1.0.1 |
| ft.getLocalImgData | Get image base64 encoding | 1.0.9 |
| ft.chooseLocation | Open map to select location | 1.0.9 |
| ft.getLocation | Get current geographic location information | 1.0.9 |
| ft.getStorage | Get local cached data | 1.0.9 |
| ft.setStorage | Set local cached data | 1.0.9 |
| ft.removeStorage | Remove local cached data | 1.0.9 |
| ft.clearStorage | Clear local cached data | 1.0.9 |
| ft.getStorageInfo | Get information about local storage | 1.0.9 |
| ft.canGoBack | Check if current H5 page can go back | 1.0.9 |
| ft.canNavigateBack | Check if current Mini-Program page can go back | 1.0.9 |
| ft.setNavigationBarTitle | Set navigation bar title | 1.0.9 |
| ft.request | Make network request | 1.3.9 |
| ft.callNativeAPI | H5 calling native methods | 1.4.1 |
When called successfully, success and complete callbacks will be called in sequence, returning:
{
errMsg: 'invokeMiniProgramAPI:ok'
}
When call fails, fail and complete callbacks will be called in sequence, returning:
{
errMsg: 'invokeMiniProgramAPI:fail'
}
Unless otherwise specified, API callbacks return in this format. Some APIs return values containing other data, please refer to the API parameter documentation below.
# API Parameter Documentation
ft.miniProgram.navigateTo(object)
Keep the current page and navigate to another page within the application.
- object parameters:
url: String - Required parameter, the path of the page to navigate tosuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.miniProgram.navigateBack(object)
Close the current page and return to the previous page or multiple pages.
- object parameters:
delta: Number - The number of pages to go back, default is 1success: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.miniProgram.switchTab(object)
Navigate to a tabBar page and close all other non-tabBar pages.
- object parameters:
url: String - Required parameter, the path of the tabBar page to navigate tosuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.miniProgram.redirectTo(object)
Close the current page and navigate to another page within the application, without keeping the current page in history.
- object parameters:
url: String - Required parameter, the path of the page to navigate tosuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.miniProgram.reLaunch(object)
Close all pages and open to a specific page within the application.
- object parameters:
url: String - Required parameter, the path of the page to opensuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.miniProgram.postMessage(object)
Send messages to the Mini-Program, which will trigger the component's message event at specific times (Mini-Program going back, component destruction, sharing).
Function parameter is Object type, for example:
ft.miniProgram.postMessage({
someKey: 'foo'
})
ft.miniProgram.postMessage({
otherKey: 'boo'
})
ft.miniProgram.getEnv(callback)
Get current environment and JSSDK version number, used to determine if the current running environment is a Mini-Program.
Parameters:
callback: Function - Callback function to receive results
Return values:
env: String - Environment type, when opened in Mini-Program, value is the string 'miniprogram', in non-Mini-Program environments, value is an empty objectversion: String - JSSDK version numbererrMsg: String - Call result
ft.miniProgram.close()
Close the Mini-Program.
ft.miniProgram.navigateToMiniProgram(object)
Navigate to another Mini-Program.
- object parameters:
appId: String - The AppID of the target Mini-Programpath: String - The path to open in the target Mini-Program, default is the homepageextraData: Object - The data to pass to the target Mini-Program, will be available in the App.onLaunch or App.onShow callbackenvVersion: String - The version of the target Mini-Program, valid values: develop (development version), trial (trial version), release (official version), default is releasesuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.miniProgram.navigateBackMiniProgram(object)
Return to the previous Mini-Program.
- object parameters:
extraData: Object - The data to pass to the previous Mini-Program, will be available in the App.onShow callbacksuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
For example, when navigating from Mini-Program A to Mini-Program B, after B returns to A using navigateBackMiniProgram with extraData parameter, A can get the jump parameters carried by Mini-Program B through the wx.getEnterOptionsSync API:
const data = wx.getEnterOptionsSync()
console.log(data)
Or get it in the onShow lifecycle of the Mini-Program App:
App({
onShow(data) {
console.log(data.referrerInfo.extraData)
}
})
ft.miniProgram.onShow(callback)
Register a callback function for the Mini-Program onShow event.
- Parameters:
callback: Function - Callback function to be executed when the Mini-Program is shown
ft.miniProgram.onHide(callback)
Register a callback function for the Mini-Program onHide event.
- Parameters:
callback: Function - Callback function to be executed when the Mini-Program is hidden
ft.miniProgram.onUnload(callback)
Register a callback function for the Mini-Program onUnload event.
- Parameters:
callback: Function - Callback function to be executed when the Mini-Program is unloaded
ft.miniProgram.onWebviewEvent(callback)
Listen for events sent by the Mini-Program, supports binding multiple functions.
- Parameters:
callback: Function - Callback function to receive events from the Mini-Program
ft.miniProgram.offWebviewEvent(callback)
Remove listener for events sent by the Mini-Program, cancels all bindings if no parameters are passed.
- Parameters:
callback: Function - Event callback function to be removed
ft.miniProgram.sendWebviewEvent(object)
Trigger the bindevent method bound to the webview tag, sending data from the H5 page to the Mini-Program.
Function parameter is Object type, for example:
ft.miniProgram.sendWebviewEvent({
someKey: 'foo'
})
ft.miniProgram.sendWebviewEvent({
otherKey: 'boo'
})
ft.downloadFile(object)
Download files from the server.
object parameters:
url: String - Download file URLheader: Object - HTTP request headertimeout: Number - Timeout in millisecondsfilePath: String - Specifies the path to save the filesuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
tempFilePath: String - Temporary file pathstatusCode: Number - HTTP status codefilePath: String - Local path of the downloaded file, consistent with the input filePatherrMsg: String - Call result ft.openDocument(object)
Open a file, supports opening multiple formats including doc, xls, ppt, pdf, etc.
- object parameters:
filePath: String - File pathfileType: String - File type, available values: doc, xls, ppt, pdf, docx, xlsx, pptxsuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.getAppletInfo(object)
Return basic information about the current mini-program.
object parameters:
success: Function - Callback function for successful API call, returns mini-program information including icon, name, description, etc.fail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
appAvatar: String - Mini-program icon URLappDescription: String - Mini-program descriptionappId: String - Mini-program IDpath: String - Mini-program page path when sharedappThumbnail: String - Mini-program cover image path, can be network path or local path, with 5:4 aspect ratioappTitle: String - Mini-program nameuserId: String - Mini-program developer IDerrMsg: String - Call result
ft.chooseImage(object)
Select images from album or take photos with camera, can specify maximum selection count, image size, and source type.
object parameters:
count: Number - Maximum number of images that can be selected, default is 9sizeType: Array - Size of selected images, available values are original (original image) and compressed (compressed image), default includes bothsourceType: Array - Source of images, available values are album (photo album) and camera (camera), default includes bothsuccess: Function - Callback function for successful API call, returns selected image informationfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
tempFilePaths: Array - Temporary file paths to selected imagestempFiles: Array - Information about selected images, including path and sizeerrMsg: String - Call result
ft.getLocalImgData(object)
Get the base64 encoded data of an image.
object parameters:
path: String - Path to the imagesuccess: Function - Callback function for successful API call, returns base64 encoded image datafail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
localData: String - Base64 encoded image dataerrMsg: String - Call result
ft.chooseLocation(object)
Open a map to select a location, returns the location information selected by the user, including latitude, longitude, location name, etc.
object parameters:
latitude: Number - Latitudelongitude: Number - Longitudesuccess: Function - Callback function for successful API call, returns location information including latitude, longitude, location name, detailed addressfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
name: String - Location nameaddress: String - Detailed addresslongitude: Number - Longitudelatitude: Number - LatitudeerrMsg: String - Call result
ft.getLocation(object)
Get current geographic location information.
object parameters:
type: String - Default is wgs84, returns GPS coordinates; gcj02 returns coordinates that can be used to open the mapsuccess: Function - Callback function for successful API call, returns location informationfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
longitude: Number - Longitudelatitude: Number - Latitudespeed: Number - Speedaccuracy: Number - Location accuracyerrMsg: String - Call result
ft.getStorage(object)
Asynchronously get the content corresponding to the specified key from local cache.
object parameters:
key: String - The specified key in local cachesuccess: Function - Callback function for successful API call, returns the content corresponding to the keyfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
data: Object/String - Content corresponding to the keyerrMsg: String - Call result
ft.setStorage(object)
Asynchronously store data in the specified key in local cache.
- object parameters:
key: String - The specified key in local cachedata: Object/String - Content to be stored, only supports native JS types, Date, and objects that can be serialized through JSON.stringifysuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.removeStorage(object)
Asynchronously delete the content of the specified key from local cache.
- object parameters:
key: String - The specified key in local cachesuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.clearStorage(object)
Clear local data cache, delete all stored data.
- object parameters:
success: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
ft.getStorageInfo(object)
Asynchronously get current storage information, including used space size, total capacity, and a list of all keys.
object parameters:
success: Function - Callback function for successful API call, returns information including keys (all keys in current storage) and currentSize (current space usage in KB)fail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
keys: Array - All keys in current storagecurrentSize: Number - Current space usage in KBerrMsg: String - Call result
ft.canGoBack(object)
Check if the current H5 page can go back to the previous page, used to determine the navigation history state of the current page.
object parameters:
success: Function - Callback function for successful API call, returns { canGoBack: true // or false }fail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
canGoBack: Boolean - Indicates whether it can go back to the previous pageerrMsg: String - Call result
ft.canNavigateBack(object)
Check if the current mini-program page can go back to the previous page, used to determine the mini-program's current page stack state.
object parameters:
success: Function - Callback function for successful API call, returns { canNavigateBack: true // or false }fail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
canNavigateBack: Boolean - Indicates whether it can go back to the previous pageerrMsg: String - Call result
ft.setNavigationBarTitle(object)
Dynamically set the title of the current mini-program page, can dynamically update the title based on page content.
- object parameters:
title: String - Page titlesuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Changes to the H5 page document.title will override the API setting, with the most recently updated title value taking precedence.
ft.request(object)
Make a network request, can request data from remote servers, supports various HTTP methods and parameter settings.
object parameters:
url: String - Developer server API addressdata: Object/String/ArrayBuffer - Request parametersheader: Object - Set request header, Referer cannot be set in the headermethod: String - HTTP request method, default is GETdataType: String - Return data format, default is jsonsuccess: Function - Callback function for successful API callfail: Function - Callback function for failed API callcomplete: Function - Callback function when API call completes
Return values:
data: Object - Data returned by the serverstatusCode: Number - HTTP status codeheader: Object - Header returned by the servererrMsg: String - Call result
ft.callNativeAPI(name, data, callback)
H5 page calling native methods, enabling interaction between H5 and native applications, can access native functionality and capabilities.
- Parameters:
name: String - API name registered by nativedata: Object - Parameters passed to the native methodcallback: Function - Callback function executed after the native method completes
ft.registNativeAPIHandler(name, callback)
Register H5 method for native to call (not recommended), enabling native applications to send messages to H5 pages and call H5 methods.
- Parameters:
name: String - Registered method namecallback: Function - Callback function executed when called by native
ft.complete()
Send load complete event to mini-program, notifying the mini-program that the H5 page has finished loading.
When the mini-program is configured with a timeout, H5 needs to notify when loading is complete, otherwise the bindtimeout event will be triggered after the timeout period.
Timeout is in milliseconds.
<web-view src="" timeout="12000" bindtimeout="timeout" />
ft.onNativeAPIHandler(name, callback)
Register H5 method for native to call, allowing native applications to call methods in the H5 page, supports registering multiple callback functions.
- Parameters:
name: String - Registered method namecallback: Function - Callback function executed when called by native
ft.offNativeAPIHandler(name, callback) Cancel registered H5 method, remove callback functions previously registered through onNativeAPIHandler.
- Parameters:
name: String - Method name to unregistercallback: Function - Callback function to cancel
# Example Code for Some APIs
ft.miniProgram.navigateTo({ url: '/path/to/page' })
ft.miniProgram.reLaunch({ url: '/path/to/page' })
ft.miniProgram.postMessage({ data: 'foo' })
ft.miniProgram.postMessage({ data: { foo: 'bar' } })
ft.miniProgram.getEnv(function(res) {
console.log(res.env)
console.log(res.version) // Supported since 1.4.18
}) // miniprogram
// Synchronous way to determine current H5 running environment
console.log(window.__fcjs_environment) // miniprogram
// Close mini-program
ft.miniProgram.close()
ft.miniProgram.navigateBackMiniProgram({
extraData: {},
success: function(res) {
console.log('navigateBackMiniProgram success callback:')
console.log(res)
}
})
ft.miniProgram.navigateToMiniProgram({
appId: '',
success: function(res) {
console.log('navigateToMiniProgram success callback:')
console.log(res)
}
})
ft.miniProgram.onShow(res => {
console.log(res)
// res.data represents the current mini-program route query
})
ft.miniProgram.onHide(res => {
// Do Some Thing
})
ft.miniProgram.onUnload(res => {
// Do Some Thing
})
ft.downloadFile({
url,
header,
timeout,
filePath
})
ft.openDocument({
filePath,
fileType
})
ft.chooseImage({
count: 1, // Default 9
sizeType: ['original', 'compressed'], // Can specify original or compressed image, default includes both
sourceType: ['album', 'camera'], // Can specify source as album or camera, default includes both
success: res => {
console.log(res)
}
})
ft.getAppletInfo({
success: res => {
console.log('getAppletInfo', res)
// {
// appAvatar = "Mini-program icon address";
// appDescription = "Mini-program description";
// appId = "Mini-program id";
// path = "Mini-program page path when shared";
// appThumbnail = "Mini-program cover image path, can be network or local path, with 5:4 aspect ratio";
// appTitle = "Mini-program name";
// userId = "Mini-program developer id";
// }
}
})
ft.chooseImage({
count: 1, // Default 9
sizeType: ['original', 'compressed'], // Can specify original or compressed image, default includes both
sourceType: ['album', 'camera'], // Can specify source as album or camera, default includes both
success: res => {
console.log(res)
window.ft.miniProgram.getLocalImgData({
path: res.tempFilePaths[0],
success: res => {
console.log(res)
}
})
}
})
// Check if current H5 page can go back to previous page
ft.canGoBack({
success: function(res) {
console.log(res)
}
})
// Check if mini-program can go back to previous page
ft.canNavigateBack({
success: function(res) {
console.log(res)
}
})
// Set mini-program page title
ft.setNavigationBarTitle({
title: 'page title'
})
ft.request({
url: 'https://some.url',
method: 'GET',
data: {
param1: 'test'
},
success: function(res) {
console.log('success', res)
},
fail: function(res) {
console.log('fail', res)
},
complete: function(res) {
console.log('complete', res)
}
})
# 2. Special Interfaces
| Interface Name | Description | Min Version |
|---|---|---|
| ft.miniProgram.onWebviewEvent | Listen for events sent by mini-program | 1.4.1 |
| ft.miniProgram.offWebviewEvent | Remove listener for mini-program events | 1.4.1 |
| ft.miniProgram.sendWebviewEvent | Trigger the bindevent method on webview tag | 1.4.1 |
| ft.callNativeAPI | H5 page calling native API | 1.4.1 |
| ft.onNativeAPIHandler | Register native calling H5 API | 1.4.20 |
| ft.offNativeAPIHandler | Cancel registered native calling H5 API | 1.4.20 |
# 2.1 H5 Page Calling Native API
Example interface name: js2AppFunction
# 2.1.1 iOS Example
[[FATClient sharedClient] fat_registerWebApi:@"js2AppFunction" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) {
NSString *name = param[@"name"];
// id params = param[@"data"];
if ([name isEqualToString:@"getLocation"]) {
// Execute location logic
// Return result to HTML
NSDictionary *dict = @{@"errno":@"403", @"errmsg":@"No permission", @"result": @{@"address":@"Guangdong Province, Shenzhen, Nanshan District, Aerospace Science and Technology Plaza"}};
callback(FATExtensionCodeSuccess, dict);
} else if ([name isEqualToString:@"getColor"]) {
// Execute other logic
// Return result to HTML
NSDictionary *dict = @{@"r":@"110",@"g":@"150",@"b":@"150"};
callback(FATExtensionCodeSuccess, dict);
}
}];
# 2.1.2 Android Example
API Example
public class WebApi extends BaseApi {
public WebApi(Context context) {
super(context);
}
@Override
public String[] apis() {
return new String[]{"js2AppFunction"}; //API name
}
@Override
public void invoke(String event, JSONObject param, ICallback callback) {
// Native operations when method is called
}
}
Kotlin
FinAppClient.extensionWebApiManager.registerApi(WebApi(this))
Java
FinAppClient.INSTANCE.getExtensionWebApiManager().registerApi(new WebApi(this));
# 2.1.3 HarmonyOS Example
API Example
const client = FinAppClient.init(
finAppConfig, // Parameter definitions can be found in HarmonyOS SDK initialization documentation
context,
entryInfo,
startMode
)
client.registerCustomApi('js2AppFunction', (args: IApiManager.IInvokeArgs) => {
const params = args.params
const callback = args.callback
console.log('customApi params', JSON.stringify(params))
callback.onSuccess({ data: 'customApi success' })
})
# 2.1.4 HTML Example
Import our bridge JSSDK file in HTML to call the registered methods above.
Example of calling registered methods in HTML:
// Complete parameter description
// name: API name registered by native
// data: Parameters passed to the native method
// callback: Callback function executed after the native method completes
ft.callNativeAPI('js2AppFunction', { name: 'getLocation' }, result => {
console.log(result)
})
# 2.2 Native Calling HTML Methods
Example interface name: app2jsFunction
# 2.2.1 iOS API
Native side calls the following API to call JS functions in HTML:
NSString *jsonParams = @""; //This should be a JSON string converted from a parameter dictionary.
NSNumber *pageId = @(1234); //This is the pageId passed from HTML
[[FATClient sharedClient] fat_callWebApi:@"app2jsFunction" paramString:jsonParams pageId:pageId handler:^(id result, NSError *error) {
}];
# 2.2.2 Android API
/**
* Native calling JS function
*
* @param appId Mini-program id
* @param funcName JS function name
* @param funcParams JS function parameters
* @param webViewId WebView id
* @param callback Callback
*/
fun callJS(appId: String, funcName: String?, funcParams: String?, webViewId: Int, callback: FinCallback<String?>)
Call Example
Kotlin
FinAppClient.appletApiManager.callJS("appId", "app2jsFunction", "funParams", 1, object : FinCallback<String?> {
override fun onSuccess(result: String?) {
Toast.makeText(context, "Call JS success: $result", Toast.LENGTH_SHORT).show()
}
override fun onError(code: Int, error: String) {
Log.d(TAG, "Call JS failed: Error code=$code, Error message=$error")
}
override fun onProgress(status: Int, info: String) {
Log.d(TAG, "Call JS in progress: Status code=$status, Info=$info")
}
})
Java
FinAppClient.INSTANCE.getAppletApiManager().callJS("appId", "app2jsFunction", "funParams", 1, new FinCallback<String>() {
@Override
public void onSuccess(String result) {
Toast.makeText(context, "Call JS success: " + result, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(int code, String error) {
Toast.makeText(context, "Call JS failed: Error code=" + code + ", Error message=" + error, Toast.LENGTH_SHORT).show();
}
@Override
public void onProgress(int status, String info) {
Log.d(TAG, "Call JS in progress: Status code=" + status + ", Info=" + info);
}
});
# 2.2.3 HTML API
Similarly, import the bridge JSSDK file in HTML, then register methods in HTML, such as a method called app2jsFunction.
// Complete parameter description
// name: Registered method name
// callback: Callback function executed when called by native, receives parameters passed from native
const callback = function(res) {
// app2jsFunction callback
// res contains data passed from native
console.log(res)
return { success: true } // Can return data to native
}
// Add listener
ft.onNativeAPIHandler('app2jsFunction', callback)
// Remove listener
ft.offNativeAPIHandler('app2jsFunction', callback)
# 2.3 H5 Page Sending Events to Mini-Program
# 2.3.1 H5 Code Example
// H5 page
// Parameter: object
// Data will be passed to the mini-program's bindevent callback function's e.detail.data
ft.miniProgram.sendWebviewEvent({
test: 123
})
# 2.3.2 Mini-Program Code Example
Logic layer
// Mini-program /pages/index/index.js
Page({
onEvent(e) {
console.log(e.detail.data.test) // 123
}
})
View layer
<!-- Mini-program /pages/index/index.fxml -->
<web-view src="https://xxx.xxx" bindevent="onEvent"></web-view>
# 2.4 Mini-Program Sending Events to H5 Page
# 2.4.1 H5 Code Example
// Parameter is callback: Callback function to receive mini-program events, parameter e contains data passed from the mini-program
function onEvent(e) {
console.log(e.test) // 123
}
// Register listener
ft.miniProgram.onWebviewEvent(onEvent)
// Remove listener
ft.miniProgram.offWebviewEvent(onEvent)
# 2.4.2 Mini-Program Code Example
// Parameter: object, represents the data to be sent to the H5 page
ft.sendWebviewEvent({ test: 123 })