The startApp operation is used to start another HTML5 app or another offline package in the current mPaaS app.
startApp API usage instruction
AlipayJSBridge.call('startApp', {
appId: '90000000',
param: {
url: '/index.html'
}
}, function(result) {
// noop
});
// To open multiple app instances:
// Include both appClearTop and startMultApp in param.
AlipayJSBridge.call('startApp', {
appId: '90000000',
param: {
url: location.href,
appClearTop: false,
startMultApp: 'YES' // Note that the value is YES, not a value of the BOOL type.
}
}, function(result) {
// noop
});
Sample code
Open an app with a transparent title bar:
<h1>Click the button to view the effect.</h1>
<a href="javascript:void(0)" class="btn dream">Open My savings.</a>
<script>
function ready(callback) {
// Call JS Bridge if it has been injected.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Listen to the injection event if it has not been injected.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function(){
document.querySelector('.dream').addEventListener('click', function() {
AlipayJSBridge.call('startApp', {
appId: '20000981',
param: {
url: '/www/dream-create.html',
// Input startup parameters.
canPullDown: true,
transparentTitle: 'auto'
}
}, function(result) {
// noop
});
});
});
</script>
Open a new app and close the current app:
<h1>Click the button to open a new app and the current app is closed.</h1>
<a href="javascript:void(0)" class="btn forest">Open Ant Forest.</a>
<script>
function ready(callback) {
// Call JS Bridge if it has been injected.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Listen to the injection event if it has not been injected.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.forest').addEventListener('click', function() {
AlipayJSBridge.call('startApp', {
appId: '60000002',
// If no URL is input, the default URL of the app is used.
param: {
transparentTitle: 'auto'
},
closeCurrentApp: true
}, function(result) {
// noop
});
});
});
</script>
By default, only one app instance is opened:
<h1>Try to open the current page again. Exit the current app and open it again.</h1>
<a href="javascript:void(0)" class="btn self">Open the current page.</a>
<script>
function ready(callback) {
// Call JS Bridge if it has been injected.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Listen to the injection event if it has not been injected.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function(){
document.querySelector('.self').addEventListener('click', function() {
AlipayJSBridge.call('startApp', {
// The current page is opened with the general app ID 20000067.
//Therefore, other 20000067 pages are closed when startApp is called.
//Actually only the current page is opened.
appId: '20000067',
param: {
url: location.href,
}
}, function(result) {
// noop
});
});
});
</script>
Open multiple pages with the same app ID:
<h1>Open multiple pages with the same app ID.</h1>
<a href="javascript:void(0)" class="btn multi">Start another app.</a>
<script>
function ready(callback) {
// Call JS Bridge if it has been injected.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Listen to the injection event if it has not been injected.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.multi').addEventListener('click', function() {
AlipayJSBridge.call('startApp', {
appId: '90000000',
param: {
url: '/index.html',
appClearTop: false,
startMultApp: 'YES' // Note that the value is YES, not a value of the BOOL type.
}
}, function(result) {
// noop
});
});
});
</script>
API
AlipayJSBridge.call('startApp', {
appId, param: {}, closeCurrentApp
}, fn)
Input parameters
Parameter | Data type | Description | Required | Default value | Baseline |
appId | string | The ID of the offline package. | Y | “” | - |
param | dictionary | The parameters of the app that you want to start. The value is defined by the specific business application. For example, if you want to open an offline package, you must specify the URL of the offline package in the param parameter. If you want to run multiple instances, see Note in this topic. | N | The data type of the value can be CHAR, BOOL, INT, or DOUBLE. | - |
closeCurrentApp | bool | Specifies whether to exit the current app before starting a new app. This parameter is used when a page serves as a transition page. | N | - | >10.1.60 |
fn | function | The callback function that is executed when the operation failed. | N | - | - |
Error code description
Error code | Description |
10 | The specified app ID is invalid. |
11 | Starting app failed. |
Note
startApp
is used to open the App, so its positioning is at the App level, which is different frompushWindow
in this regard.By default, if the current App has already been opened, when the App is opened again using
startApp
, an operation similar to restarting will be performed. That is to say, it is impossible to run two instances with the same appId at the same time.If an appId needs to run multiple instances, please add the
appClearTop=false&startMultApp=YES
option in the param parameter.