全部產品
Search
文件中心

SuperApp:基礎

更新時間:Sep 03, 2025

本文介紹基礎類WVBase相關的JS API,供您在開發小程式時參考。基礎類WVBase相關JS API提供文本複製粘貼、介面UI背景顏色、安裝指導應用程式、目前的版本API是否支援等能力。

WVBase.copyToClipboard

將指定的文本複製到剪貼簿。

輸入參數

  • [string]text:要複製到剪貼簿中的文本。

回調參數

無回調參數,如果成功複製到剪貼簿,則進入success回調,否則進入failure回調。

var params = {
        text: "text to copy"
};
window.WindVane.call('WVBase', 'copyToClipboard', params, function(e) {
        alert('success' + JSON.stringify(e));
}, function(e) {
        alert('failure' + JSON.stringify(e));
});

WVBase.isInstall

判斷是否已安裝指定的應用程式。

說明

在 iOS 9或更高版本系統中,只有在info.plistLSApplicationQueriesSchemes中配置過的scheme,才能夠正確判斷引用是否安裝。

輸入參數

  • [string] ios:iOS平台的應用程式標記,使用的是schema,例如 'taobao://'

  • [string] android:Android 平台的應用程式標記,使用的是包名,例如 'com.taobao.taobao'

回調參數

無回調參數,如果已安裝指定應用程式,則進入success 回調,否則進入failure 回調。

var params = {
        // iOS 平台的應用程式標記
        ios: 'taobao://',
        // Android 平台的應用程式標記
        android: 'com.taobao.taobao'
};
window.WindVane.call('WVBase', 'isInstall', params, function(e) {
        alert('success');
}, function(e) {
        alert('failure');
});

WVBase.isAppsInstalled

判斷是否已安裝指定的多個應用程式。

說明

在 iOS 9或更高版本系統中,只有在info.plistLSApplicationQueriesSchemes中配置過的scheme,才能夠正確判斷引用是否安裝。

輸入參數

  • [object] appName:要判斷是否安裝的App,其值是一個對象,包含以下屬性:

    • [string] ios:iOS平台的應用程式標記,使用的是 schema,例如'taobao://'

    • [string] android:Android平台的應用程式標記,使用的是包名,例如'com.taobao.taobao'

回調參數

回調參數將會在回調方法中傳遞,如果成功檢測應用程式是否安裝,則進入success回調,否則進入failure回調。

  • [boolean] appName:之前傳遞的App是否安裝。

var params = {
        taobao: {
                ios: 'taobao://',
                android: 'com.taobao.taobao'
        },
        tmall: {
                ios: 'tmall://',
                android: 'com.tmall.tmall'
        }
};
window.WindVane.call('WVBase', 'isAppsInstalled', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.notify

說明

該API僅適用於WindVane iOS。

document引髮指定名稱和參數的事件。

輸入參數

  • [string] event:要引發的事件名稱。

  • [object] param:要引發的事件參數。

回調參數

無回調參數,也不會進入successfailure回調。

監聽事件

event 指定的事件,事件參數為param指定的對象。

document.addEventListener('MyNotifyName', function(e) {
        alert(JSON.stringify(e.param));
}, false);

var params = {
        // 要引發的事件名稱
        event: 'MyNotifyName',
        // 要引發的事件參數
        param: { MyEventParam: 'paramValue' }
};
window.WindVane.call('WVBase', 'notify', params);

WVBase.openBrowser

說明

該API僅適用於WindVane iOS。

開啟指定URL的Safari新視窗。

輸入參數

  • [string] url:要在Safari中顯示的URL。

重要

僅需要確保在Safari中開啟的URL,才使用此JSBridge。其它情況都請直接使用<a>連結、設定location.href或者iframe 的方式進行跳轉。

回調參數

無回調參數,如果成功開啟了指定URL,則進入success回調,否則進入failure回調。

var params = {
        // 要在瀏覽器中顯示的 URL
        url: 'http://www.baidu.com'
};
window.WindVane.call('WVBase', 'openBrowser', params, function(e) {
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.setBackgroundColor

說明

該API僅適用於WindVane iOS。

設定WebView的背景顏色。

輸入參數

  • [string] color:WebView 背景顏色的十六進位顏色值,支援0X#首碼。

  • [number] alpha:*[可選]*WebView 背景不透明度,有效範圍為 [0, 1]

回調參數

無回調參數,如果成功設定背景透明度,則進入success回調,否則進入failure回調。

var params = {
        color: 'FF0000',
        alpha: 0.3
};
window.WindVane.call('WVBase', 'setBackgroundColor', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.canIUse

說明

該API只在Windvane Android 1.0.3.4以上版本有效。

判斷傳入的API在目前的版本是否支援。

輸入參數

  • [string] api:API的名稱,如WVBase,WVMotion等。

  • [string] method:*[可選]* api中的方法,如isWindVaneSDK,copyToClipboard等。如果不傳入method,則只判斷目前的版本是否支援API。

回調參數

  • [boolean] canUse:true代表目前的版本支援傳入的API,false代表不支援。

var params = {
        api: 'WVMotion',
        method: 'vibrate'
};
window.WindVane.call('WVBase', 'canIUse', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVMiniApp.close

關閉小程式。

輸入參數:

無。

回調參數:

無。

window.WindVane.call('WVMiniApp', 'close', {}, function(e) {
  			alert('success');
}, function(e) {
  			alert('failure');
});