### Create and Manage Barcode Scanner (Example) Source: https://www.html5plus.org/doc/zh_cn/barcode An example demonstrating how to create, append, start, and update a barcode scanner in a web application using the HTML5+ API. It includes the creation of the scanner, appending it to the current view, starting the scan, and updating its styles. ```javascript var barcode = null; // 创建Barcode扫码控件 function createBarcode() { if(!barcode){ barcode = plus.barcode.create('barcode', [plus.barcode.QR], { top:'100px', left:'0px', width: '100%', height: '500px', position: 'static' }); plus.webview.currentWebview().append(barcode); } barcode.start(); } // 更新Barcode扫码控件 function updateBarcode() { barcode.setStyle({ top:'200px' // 调整扫码控件的位置 }); } ``` -------------------------------- ### Create Contact Example Source: https://www.html5plus.org/doc/zh_cn/contacts This HTML example shows how to create a new contact using the `addressbook.create()` method obtained after getting the address book object. It then sets the contact's name and phone number before saving it. The `plusready` event ensures API availability, and it first retrieves the address book. ```javascript Contacts Example ``` -------------------------------- ### Get File System and Create/Read File Source: https://www.html5plus.org/doc/zh_cn/io An HTML example demonstrating how to request a file system, create a file named 'config.xml', and read its content using FileReader. This involves event listeners for 'plusready'. ```html File Example Request file system ``` -------------------------------- ### start Source: https://www.html5plus.org/doc/zh_cn/video Starts the live streaming process. ```APIDOC ## pusher.start(successCB, errorCB) ### Description Initiates the live streaming process. If the pusher is already in a streaming state, this operation will have no effect. ### Method `pusher.start(successCB, errorCB)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **successCB** (Function) - Required - Callback function executed upon successful start of streaming. This function takes no arguments. - **errorCB** (Function) - Optional - Callback function executed upon failure to start streaming. This function receives an event object with `code` (error code) and `message` (error description). ### Request Example ```javascript // Start streaming function startPusher() { pusher.start(function() { console.log('Start pusher success!'); }, function(e) { console.log('Start pusher failed: ' + JSON.stringify(e)); }); } ``` ### Response #### Success Response (200) void: This method does not return a value. #### Response Example N/A ``` -------------------------------- ### XMLHttpRequest Example with State Changes Source: https://www.html5plus.org/doc/zh_cn/xhr A full HTML example demonstrating the usage of XMLHttpRequest. It includes setting up an `onreadystatechange` event handler to monitor the request's progress and handling the final response based on the `status` code. The example shows how to open a GET request to a specified URL and send it. ```html ``` -------------------------------- ### Start iBeacon Discovery and Monitor Updates (JavaScript) Source: https://www.html5plus.org/doc/zh_cn/ibeacon This example demonstrates how to initiate iBeacon device discovery and set up a listener to receive updates on detected beacons. It uses the plus.ibeacon API and displays found beacon UUIDs using a native alert. It requires the 'plusready' event to be fired before execution. ```javascript document.addEventListener('plusready', onPlusReady, false); function onPlusReady(){ } function listenerBeacons(){ plus.ibeacon.startBeaconDiscovery({ success:function(){ plus.ibeacon.onBeaconUpdate(function(e){ var beacons = e.beacons; var uuids = null; for(var i in beacons){ if(uuids){ uuids += ', '+beacons[i].uuid; }else{ uuids = beacons[i].uuid; } } plus.nativeUI.alert('Beacons updated: '+uuids); }); }, failed: function(e){ plus.nativeUI.alert('start error: '+JSON.stringify(e)); } }); } ``` -------------------------------- ### WidgetOptions Source: https://www.html5plus.org/doc/zh_cn/runtime Options for application installation, including force installation and version checking. ```APIDOC ## WidgetOptions ### Description JSON object to configure application installation, including AppID validation and version checking. ### Properties - **force** (Boolean) - Optional - Whether to force installation without version checking. If `false`, installation will be aborted if the new version is not higher than the existing one. Defaults to `false`. Only effective when installing `wgt` and `wgtu` files. ``` -------------------------------- ### iOS Native.js Example Source: https://www.html5plus.org/doc/zh_cn/ios Example demonstrating how to use iOS Native.js to handle player authentication and retrieve player information. ```APIDOC ## iOS Native.js Example ### Description This example shows how to use Native.js to interact with iOS Game Center features, including player authentication and retrieving player information upon successful authentication. ### Method JavaScript (within uni-app) ### Endpoint N/A (Client-side implementation) ### Parameters None ### Request Example ```html iOS Native.js ``` ### Response N/A (Client-side event handling) ``` -------------------------------- ### Application Information and Installation Source: https://www.html5plus.org/doc/zh_cn/runtime Retrieve application properties, install applications, and manage the application lifecycle. ```APIDOC ## getProperty ### Description Retrieves application information for a specified AppID. ### Method `plus.runtime.getProperty(appid, getPropertyCB)` ### Endpoint N/A (Client-side function) ### Parameters - **appid** (String) - Required. The AppID of the application. - **getPropertyCB** (GetPropertyCallBack) - Required. Callback function to receive application information. ### Return Value `void` ### Example ```javascript function getAppInfo() { plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) { var wgtStr = "appid:" + wgtinfo.appid; wgtStr += "
version:" + wgtinfo.version; wgtStr += "
name:" + wgtinfo.name; wgtStr += "
description:" + wgtinfo.description; wgtStr += "
author:" + wgtinfo.author; wgtStr += "
email:" + wgtinfo.email; wgtStr += "
features:" + wgtinfo.features; console.log(wgtStr); }); } ``` --- ## install ### Description Installs an application package (wgt, wgtu, or apk). ### Method `plus.runtime.install(filePath, options, installSuccessCB, installErrorCB)` ### Endpoint N/A (Client-side function) ### Parameters - **filePath** (String) - Required. The local path to the installation file (e.g., '.wgt', '.wgtu', '.apk'). - **options** (WidgetOptions) - Optional. Parameters for application installation. - **installSuccessCB** (InstallSuccessCallback) - Optional. Callback function for successful installation. - **installErrorCB** (InstallErrorCallback) - Optional. Callback function for installation failure. ### Return Value `void` ### Platform Support - Android - 2.2+ (Supported). Requires `android.permission.INSTALL_PACKAGES` and `android.permission.REQUEST_INSTALL_PACKAGES` permissions. - iOS - 4.3+ (Supported). Does not support direct IPA installation; requires redirection to the App Store. --- ## quit ### Description Exits the application and returns to the system desktop or the previous screen. ### Method `plus.runtime.quit()` ### Endpoint N/A (Client-side function) ### Parameters None ### Return Value `void` ### Platform Support - Android - 2.2+ (Supported). - iOS - 4.3+ (Supported for 5+ APP, but does not function; Home button must be used to exit). ### Example ```javascript function quitApp() { plus.runtime.quit(); } ``` --- ## restart ### Description Restarts the current application, returning to the home page. ### Method `plus.runtime.restart()` ### Endpoint N/A (Client-side function) ### Parameters None ### Return Value `void` ``` -------------------------------- ### Get Application Information Example Source: https://www.html5plus.org/doc/zh_cn/runtime Example demonstrating how to retrieve and display application information using plus.runtime.getProperty. It logs details like appid, version, name, description, author, email, license, licensehref, and features to the console. Supported on Android (2.2+) and iOS (4.3+). ```javascript // 获取应用信息 function getAppInfo() { plus.runtime.getProperty( plus.runtime.appid, function(wgtinfo){ //appid属性 var wgtStr = "appid:"+wgtinfo.appid; //version属性 wgtStr += "
version:"+wgtinfo.version; //name属性 wgtStr += "
name:"+wgtinfo.name; //description属性 wgtStr += "
description:"+wgtinfo.description; //author属性 wgtStr += "
author:"+wgtinfo.author; //email属性 wgtStr += "
email:"+wgtinfo.email; //licence属性 wgtStr += "
license:"+wgtinfo.license; //licensehref属性 wgtStr += "
licensehref:"+wgtinfo.licensehref; //features 属性 wgtStr += "
features:"+wgtinfo.features; console.log( wgtStr ); } ); } ``` -------------------------------- ### startAll Source: https://www.html5plus.org/doc/zh_cn/downloader Starts all download tasks that are in a 'not started' or 'paused' state. ```APIDOC ## POST /api/downloader/startAll ### Description Starts all download tasks that are currently in a 'not started' or 'paused' state. If the number of download tasks exceeds the concurrent processing limit, excess tasks will be scheduled and started as others complete, based on priority. ### Method POST ### Endpoint /api/downloader/startAll ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **message** (String) - Indicates the operation was successful. #### Response Example ```json { "message": "All download tasks started successfully." } ``` ``` -------------------------------- ### NativeObj View Creation Example Source: https://www.html5plus.org/doc/zh_cn/nativeobj Example demonstrating how to create a native View control and draw an input field within it. ```APIDOC ## POST /api/nativeobj/createView ### Description Creates a native View control and draws an input field within it. ### Method POST ### Endpoint /api/nativeobj/createView ### Parameters #### Request Body - **options** (object) - Required - Configuration options for the View. - **input_styles** (object) - Optional - Styles for the input field. - **type** (string) - Required - The type of element to draw, e.g., 'input'. ### Request Example ```json { "options": {"top":"0px","left":"0px","height":"44px","width":"100%"}, "input_styles": {"fontSize":"16px"}, "type": "input" } ``` ### Response #### Success Response (200) - **view_id** (string) - The ID of the created view. #### Response Example ```json { "view_id": "test" } ``` ``` -------------------------------- ### Get Client Push Identifier Information Example (JavaScript) Source: https://www.html5plus.org/doc/zh_cn/push An example demonstrating how to retrieve client push identifier information using `plus.push.getClientInfo()` and log it to the console. It also includes setting up a 'click' event listener. ```javascript document.addEventListener(‘plusready’, function(){ // extension API loading complete, now you can call extension APIs normally // Get client identifier information var info = plus.push.getClientInfo(); alert( JSON.stringify( info ) ); // Add listener for the event of clicking a message from the system message center to start the app plus.push.addEventListener(‘click’, function(msg){ // Analyze msg.payload to process business logic alert('You clicked: ' + msg.content); }, false); }, false); ``` -------------------------------- ### Read Directory Entries Example Source: https://www.html5plus.org/doc/zh_cn/io An HTML example showing how to request a file system, create a DirectoryReader, and then read all entries within the root directory, logging their names. ```html File Example Request file system ``` -------------------------------- ### Install Application Package (JavaScript) Source: https://www.html5plus.org/doc/zh_cn/runtime Installs application packages including WGT, WGTU, and APK files. Requires local file paths and specific Android permissions for APK installation. iOS does not support direct IPA installation. ```javascript void plus.runtime.install(filePath, options, installSuccessCB, installErrorCB); ``` -------------------------------- ### start Source: https://www.html5plus.org/doc/zh_cn/uploader Starts the upload task. This method initiates the file transfer. ```APIDOC ## POST /upload/{taskId}/start ### Description Starts the upload task. This method initiates the file transfer. If the task is already in progress or completed, this method will have no effect. ### Method POST ### Endpoint /upload/{taskId}/start ### Parameters #### Path Parameters - **taskId** (String) - Required - The ID of the upload task to start. #### Query Parameters None #### Request Body None ### Request Example ```json {} // Empty request body ``` ### Response #### Success Response (200) - **status** (String) - Indicates the status of the start operation (e.g., "started"). #### Response Example ```json { "status": "started" } ``` ``` -------------------------------- ### plus.nativeObj.View Creation Example Source: https://www.html5plus.org/doc/zh_cn/nativeobj Example demonstrating how to create and draw content onto a native View object using HTML5 Plus. ```APIDOC ## plus.nativeObj.View Creation ### Description Creates and displays a native View control, and draws rich text content onto it. ### Method `plus.nativeObj.View` ### Endpoint N/A (Client-side API) ### Parameters #### Path Parameters - **`id`** (String) - Required - The unique identifier for the view. - **`style`** (Object) - Required - Styles for the view. Properties include `top`, `left`, `height`, `width`. #### Query Parameters None #### Request Body None ### Request Example ```javascript function createView(){ var view = new plus.nativeObj.View('test',{top:'0px',left:'0px',height:'44px',width:'100%'}); var richtext = '文本
链接
'; view.drawRichText(richtext, {top:'0px',left:'0px',width:'100%',height:'wrap_content'}, {family:'Times New Roman',fontSrc:'_www/font.ttf',onClick:function(e){ console.log("Clicked: "+JSON.stringify(e)); }}); view.show(); } ``` ### Response #### Success Response (void) - The view is created and displayed. No explicit return value. #### Response Example (No direct response, visual output is the created view) ``` -------------------------------- ### Webview Drag and Show/Hide Example Source: https://www.html5plus.org/doc/zh_cn/webview Example demonstrating how to use drag gestures to show and hide webview windows. This includes setting up drag listeners for both showing and hiding windows. ```APIDOC ## Webview Window Drag and Show/Hide ### Description This example illustrates how to implement drag gestures to control the display of webview windows. It shows how to set up a swipe gesture to reveal a new window and another gesture to hide it. ### Method JavaScript API ### Endpoint N/A (Client-side API) ### Parameters N/A ### Request Example ```html Webview Example 左滑可打开新页面 ``` ### Response N/A (Client-side execution) ``` -------------------------------- ### Install Application Success Callback Source: https://www.html5plus.org/doc/zh_cn/runtime Callback function executed upon successful application installation. It receives WidgetInfo containing details about the installed application. Supported on Android (2.2+) and iOS (4.3+). On Android, this callback is not triggered for APK installations. ```javascript void onSuccess(widgetInfo){ // Code here } ``` -------------------------------- ### Monitor iBeacon Service Changes and Control Discovery (JavaScript) Source: https://www.html5plus.org/doc/zh_cn/ibeacon This example shows how to listen for changes in the iBeacon service status and provides functions to start and stop the discovery of iBeacon devices. It logs service status changes and discovery actions to the console. The code relies on the 'plusready' event for initialization. ```javascript document.addEventListener('plusready', onPlusReady, false); function onPlusReady(){ plus.ibeacon.onBeaconServiceChange(function(e){ console.log('BeaconServiceChanged: available='+e.available+', discovering='+e.discovering); }); } function startBeaconDiscovery(){ plus.ibeacon.startBeaconDiscovery({ success: function(){ console.log('start success'); }, failed: function(e){ console.log('start error: '+JSON.stringify(e)); } }); } function stopBeaconDiscovery(){ plus.ibeacon.stopBeaconDiscovery({ success: function(){ console.log('stop success'); }, failed: function(e){ console.log('stop error: '+JSON.stringify(e)); } }); } ``` -------------------------------- ### Install Payment Service (JavaScript) Source: https://www.html5plus.org/doc/zh_cn/payment Installs the necessary service for a specific payment channel. This is used when a payment channel requires a system-level service or application to be installed (e.g., Alipay client). ```javascript void pay.installService(); ``` -------------------------------- ### NativeObj View Example Source: https://www.html5plus.org/doc/zh_cn/nativeobj This example demonstrates how to create, update, and close a native object View using HTML5 Plus. ```APIDOC ## NativeObj View API ### Description Provides methods to create, update, and close native object Views. ### Methods #### createView() - **Description**: Creates and displays a new native View with specified properties and draws a rectangle on it. - **Example**: ```html ``` #### updateView() - **Description**: Updates the style and redraws a portion of an existing native View. - **Example**: ```html ``` #### closeView() - **Description**: Closes and destroys the native View. - **Example**: ```html ``` ### Response Example ```json { "message": "View operation successful" } ``` ``` -------------------------------- ### Create and Send Email Example Source: https://www.html5plus.org/doc/zh_cn/messaging An HTML example demonstrating how to create an Email message object and send it using `plus.messaging.sendMessage`. This example includes optional success and error callbacks to alert the user about the sending status. ```html Messaging Example ``` -------------------------------- ### Webview Animation Example Source: https://www.html5plus.org/doc/zh_cn/webview Example demonstrating how to perform combined animations between two webview windows using the HTML5 Plus API. ```APIDOC ## Webview Window Animation ### Description This section demonstrates how to execute combined animations between two webview windows. It includes creating a new window and then animating the current window off-screen while bringing the new window into view. ### Method JavaScript API ### Endpoint N/A (Client-side API) ### Parameters N/A ### Request Example ```html Webview Example



在新窗口中可以右滑返回(新窗口移动到屏幕外) ``` ### Response N/A (Client-side execution) ``` -------------------------------- ### Fingerprint Authentication HTML and JavaScript Example Source: https://www.html5plus.org/doc/zh_cn/fingerprint This HTML and JavaScript example demonstrates how to initiate fingerprint authentication using the H5 plus API. It includes a 'plusReady' function that automatically calls the fingerprint.authenticate method upon successful H5 plus initialization. ```html Fingerprint Example 指纹识别认证 ``` -------------------------------- ### Get Webview Share Options - JavaScript Example Source: https://www.html5plus.org/doc/zh_cn/webview Illustrates how to get the share options configured for a Webview window using `getShareOptions()`. The example first sets the share options and then retrieves them, displaying the result in an alert. ```javascript var ws=null; // H5 plus事件处理 function plusReady(){ ws=plus.webview.currentWebview(); ws.setShareOptions({title:'分享的标题',href:'http://www.dcloud.io/'}); } if(window.plus){ plusReady(); }else{ document.addEventListener('plusready', plusReady, false); } // 获取窗口的分享参数 function getShareOptions(){ var t = ws.getShareOptions(); alert(t?"未设置":JSON.stringify(t)); } ``` -------------------------------- ### Create and Listen to LivePusher Events Source: https://www.html5plus.org/doc/zh_cn/video This example shows how to initialize a LivePusher component for live streaming and set up event listeners for state changes, network status, and errors. It's designed for use within a uni-app environment. ```javascript pusher = new plus.video.LivePusher('pusher',{ url:'rtmp://testlivesdk.v0.upaiyun.com/live/upyunb' }); pusher.addEventListener('statechange', function(e){ console.log('statechange: '+JSON.stringify(e)); }, false); pusher.addEventListener('netstatus', function(e){ console.log('netstatus: '+JSON.stringify(e)); }, false); pusher.addEventListener('error', function(e){ console.log('error: '+JSON.stringify(e)); }, false); ``` -------------------------------- ### Example Usage: Get Current Position Source: https://www.html5plus.org/doc/zh_cn/geolocation Demonstrates how to get the current device's position using the Baidu positioning module. ```APIDOC ## GET /geolocation/currentPosition ### Description Retrieves the current geographical position of the device. ### Method GET ### Endpoint `plus.geolocation.getCurrentPosition( successCallback, errorCallback, options ) ` ### Parameters #### Success Callback - **successCallback** (Function) - A function that takes a `Position` object as an argument upon successful retrieval of the location. #### Error Callback - **errorCallback** (Function) - A function that takes a `GeolocationError` object as an argument if an error occurs during location retrieval. #### Options (Optional) - **options** (PositionOptions) - An object containing configuration options for retrieving the position. See `PositionOptions` for details. ### Request Example ```javascript document.addEventListener('plusready', function() { plus.geolocation.getCurrentPosition(function(p){ console.log('Latitude: ' + p.coords.latitude + '\n' + 'Longitude: ' + p.coords.longitude + '\n' + 'Altitude: ' + p.coords.altitude); }, function(e){ console.log('Geolocation error: ' + e.message); }, {provider:'baidu'}); }, false); ``` ### Response #### Success Response (Position Object) - **coords** (Coordinates) - Contains the latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, and speed of the device. - **address** (Address) - Contains the address information (if `geocode` option is true). - **addresses** (String) - A formatted string representing the address (if `geocode` option is true). - **timestamp** (Number) - The timestamp when the position was retrieved. ``` -------------------------------- ### Get Address Book Object Example Source: https://www.html5plus.org/doc/zh_cn/contacts This HTML example demonstrates how to get an address book object using the `plus.contacts.getAddressBook` method. It specifies the type of address book to retrieve (phone contacts) and includes callbacks for success and error handling. The `plusready` event ensures the API is available. ```javascript Contacts Example ``` -------------------------------- ### POST /api/speech/startRecognize Source: https://www.html5plus.org/doc/zh_cn/speech Starts the speech recognition process. It takes an options object to configure the recognition engine and optional callback functions for success and error scenarios. ```APIDOC ## POST /api/speech/startRecognize ### Description Starts the speech recognition process. It takes an options object to configure the recognition engine and optional callback functions for success and error scenarios. ### Method POST ### Endpoint plus.speech.startRecognize( options, successCB, errorCB ) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (SpeechRecognizeOptions) - Required - Voice recognition parameters to control various technical parameters of the voice engine. - **successCB** (RecognitionSuccessCallback) - Optional - Callback function executed when the speech recognition engine successfully recognizes data, returning the recognized text content. - **errorCB** (RecognitionErrorCallback) - Optional - Callback function executed when the speech recognition engine fails to recognize data, returning error information. ### Request Example ```javascript var options = {}; options.engine = 'iFly'; plus.speech.startRecognize(options, function(s){ console.log(s); }, function(e){ console.error(e.message); }); ``` ### Response #### Success Response (200) Void: No return value. #### Response Example None (as the function returns void and uses callbacks) ``` -------------------------------- ### Create and Manage FullScreenVideoAd (JavaScript Example) Source: https://www.html5plus.org/doc/zh_cn/ad An example demonstrating how to create, load, display, and handle events for a full-screen video ad. It includes listeners for ad loading success, errors, and closing events, with logic to manage the ad object's lifecycle and provide user feedback. ```javascript var adFull = null; function fullVideoAd(){ if(adFull){ console.log('正在加载全屏视频广告'); return; } console.log('#全屏视频广告#'); adFull = plus.ad.createFullScreenVideoAd({adpid:'1507000611'}); //1507000611是HBuilder测试基座使用的广告位,正式环境下请使用在uni-AD后台申请的 adFull.onLoad(function(){ console.log('加载成功') adFull.show(); }); adFull.onError(function(e){ console.log('加载失败: '+JSON.stringify(e)); adFull.destroy(); adFull = null; }); adFull.onClose(function(e){ if(e.isEnded){ console.log('全屏视频播放完成'); plus.nativeUI.toast('全屏视频播放完成'); //这里实现完成全屏视频逻辑 }else{ console.log('全屏视频未播放完成关闭!') } adFull.destroy(); adFull = null; }); adFull.load(); } ``` -------------------------------- ### Get Current Image Index Example (HTML/JavaScript) Source: https://www.html5plus.org/doc/zh_cn/nativeobj Provides an example of how to create an ImageSlider and then retrieve and log the index of the currently displayed image. This involves using `currentImageIndex` and accessing the image data. ```html NativeObj Example
``` -------------------------------- ### Get Ads Source: https://www.html5plus.org/doc/zh_cn/ad Fetches ad data for display. It accepts an options object and provides callback functions for success and error scenarios. The example demonstrates how to use this function to get ad data and then bind it to an AdView for rendering. ```APIDOC ## POST /api/ads/getAds ### Description Fetches ad data based on the provided options. This function is crucial for populating ad views with relevant content. ### Method POST ### Endpoint plus.ad.getAds ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (AdsOptions) - Required - Object containing parameters for fetching ads, such as adpid, width, and count. - **successCB** (GetAdsSuccessCallback) - Optional - Callback function invoked when ad data is successfully retrieved. - **errorCB** (AdErrorCallback) - Optional - Callback function invoked when there is an error retrieving ad data. ### Request Example ```javascript plus.ad.getAds({ adpid: '1111111111', width: '100%', count: 1 }, function(e) { console.log('获取广告成功: ' + JSON.stringify(e)); // Handle success }, function(e) { console.log('获取广告失败: ' + JSON.stringify(e)); // Handle error }); ``` ### Response #### Success Response (200) - **ads** (Array) - An array of ad data objects. #### Response Example ```json { "ads": [ { "description": "A brief description of the ad.", "provider": "csj", "showMode": "lage", "title": "Example Ad Title" } ] } ``` ``` -------------------------------- ### Get Webview Favorite Options - JavaScript Example Source: https://www.html5plus.org/doc/zh_cn/webview Demonstrates how to retrieve the favorite options for a Webview window using `getFavoriteOptions()`. The example includes setting favorite options first and then retrieving them. It alerts the user if options are set or not. ```javascript var ws=null; // H5 plus事件处理 function plusReady(){ ws=plus.webview.currentWebview(); ws.setFavoriteOptions({title:'收藏页标题',href:'http://www.dcloud.io/'}); } if(window.plus){ plusReady(); }else{ document.addEventListener('plusready', plusReady, false); } // 获取窗口的分享参数 function getFavoriteOptions(){ var t = ws.getFavoriteOptions(); alert(t?"未设置":JSON.stringify(t)); } ``` -------------------------------- ### InstallSuccessCallback Source: https://www.html5plus.org/doc/zh_cn/runtime Callback function executed upon successful application installation. ```APIDOC ## InstallSuccessCallback ### Description Callback function invoked when an application installation is successful. ### Parameters - **widgetInfo** (WidgetInfo) - Required - Information about the installed application. ### Return Value void : No return value. ### Platform Support - Android - 2.2+ (Supported): Supported, but not triggered if the installation file is an APK. - iOS - 4.3+ (Supported): Supported. ``` -------------------------------- ### Get Second Home Webview Object Source: https://www.html5plus.org/doc/zh_cn/webview In a dual-homepage setup, this function returns the second primary WebviewObject. If not in a dual-homepage mode, it returns undefined. It takes no parameters. ```javascript WebviewObject plus.webview.getSecondWebview(); // 获取应用第二个首页窗口对象 var h=plus.webview.getSecondWebview(); if(h){ console.log('应用第二个首页Webview窗口:'+h.getURL()); }else{ console.log('应用不存在第二个首页Webview窗口'); } ``` -------------------------------- ### Create and Render AdView - JavaScript Source: https://www.html5plus.org/doc/zh_cn/ad Example demonstrating the creation of an AdView, appending it to the Webview, setting rendering listeners, fetching ad data, and binding it to the AdView for rendering. This involves setting initial dimensions and updating them upon successful rendering. ```javascript var adView = null; //创建并渲染广告 function doCreateAd(){ adView = plus.ad.createAdView({ top:adDom.offsetTop+'px', left:'0px', width:'100%', height:'0px', position: 'static' }); plus.webview.currentWebview().append(adView); adView.setRenderingListener(function(e){ outLine('渲染广告完成: '+JSON.stringify(e)); if(0 != e.result){ outLine('渲染失败!'); }else{ adView.setStyle({height:e.height+'px'}); adDom.style.height = e.height+'px'; } }); plus.ad.getAds({adpid:'1111111111',width:'100%',count:1}, function(e){ outLine('获取广告成功: '+JSON.stringify(e)); if(!e || !e.ads || e.ads.length<1){ outLine('无广告数据!'); }else{ outLine('开始渲染广告'); adView.renderingBind(e.ads[0]); } }, function(e){ outLine('获取广告失败: '+JSON.stringify(e)); }); } ``` -------------------------------- ### Get Remote File URL (JavaScript) Source: https://www.html5plus.org/doc/zh_cn/io Generates a network-accessible URL for a file, typically starting with 'http://localhost:13131/'. This is useful for remote access or sharing. ```javascript // Get the remote URL for this file var fileURL = entry.toRemoteURL(); plus.console.log(dirURL); ``` -------------------------------- ### Get Webview Style - JavaScript Example Source: https://www.html5plus.org/doc/zh_cn/webview Shows how to retrieve the style properties of a Webview window using the `getStyle()` method. The retrieved style object is then displayed using an alert. ```javascript var ws=null; // H5 plus事件处理 function plusReady(){ ws=plus.webview.currentWebview(); } if(window.plus){ plusReady(); }else{ document.addEventListener('plusready', plusReady, false); } // 获取Webview窗口的样式 function getStyle() { var style=ws.getStyle(); alert( JSON.stringify(style) ); } ```