All Products
Search
Document Center

Start other application

Last Updated: Feb 20, 2021

The startApp operation is used to start another HTML5 app or another offline package in the current mPaaS app.

startApp API usage instruction

  1. AlipayJSBridge.call('startApp', {
  2. appId: '90000000',
  3. param: {
  4. url: '/index.html'
  5. }
  6. }, function(result) {
  7. // noop
  8. });
  9. // To open multiple app instances:
  10. // Include both appClearTop and startMultApp in param.
  11. AlipayJSBridge.call('startApp', {
  12. appId: '90000000',
  13. param: {
  14. url: location.href,
  15. appClearTop: false,
  16. startMultApp: 'YES' // Note that the value is YES, not a value of the BOOL type.
  17. }
  18. }, function(result) {
  19. // noop
  20. });

Sample code

  • Open an app with a transparent title bar:
  1. <h1>Click the button to view the effect.</h1>
  2. <a href="javascript:void(0)" class="btn dream">Open My savings.</a>
  3. <script>
  4. function ready(callback) {
  5. // Call JS Bridge if it has been injected.
  6. if (window.AlipayJSBridge) {
  7. callback && callback();
  8. } else {
  9. // Listen to the injection event if it has not been injected.
  10. document.addEventListener('AlipayJSBridgeReady', callback, false);
  11. }
  12. }
  13. ready(function(){
  14. document.querySelector('.dream').addEventListener('click', function() {
  15. AlipayJSBridge.call('startApp', {
  16. appId: '20000981',
  17. param: {
  18. url: '/www/dream-create.html',
  19. // Input startup parameters.
  20. canPullDown: true,
  21. transparentTitle: 'auto'
  22. }
  23. }, function(result) {
  24. // noop
  25. });
  26. });
  27. });
  28. </script>
  • Open a new app and close the current app:
  1. <h1>Click the button to open a new app and the current app is closed.</h1>
  2. <a href="javascript:void(0)" class="btn forest">Open Ant Forest.</a>
  3. <script>
  4. function ready(callback) {
  5. // Call JS Bridge if it has been injected.
  6. if (window.AlipayJSBridge) {
  7. callback && callback();
  8. } else {
  9. // Listen to the injection event if it has not been injected.
  10. document.addEventListener('AlipayJSBridgeReady', callback, false);
  11. }
  12. }
  13. ready(function() {
  14. document.querySelector('.forest').addEventListener('click', function() {
  15. AlipayJSBridge.call('startApp', {
  16. appId: '60000002',
  17. // If no URL is input, the default URL of the app is used.
  18. param: {
  19. transparentTitle: 'auto'
  20. },
  21. closeCurrentApp: true
  22. }, function(result) {
  23. // noop
  24. });
  25. });
  26. });
  27. </script>
  • By default, only one app instance is opened:
  1. <h1>Try to open the current page again. Exit the current app and open it again.</h1>
  2. <a href="javascript:void(0)" class="btn self">Open the current page.</a>
  3. <script>
  4. function ready(callback) {
  5. // Call JS Bridge if it has been injected.
  6. if (window.AlipayJSBridge) {
  7. callback && callback();
  8. } else {
  9. // Listen to the injection event if it has not been injected.
  10. document.addEventListener('AlipayJSBridgeReady', callback, false);
  11. }
  12. }
  13. ready(function(){
  14. document.querySelector('.self').addEventListener('click', function() {
  15. AlipayJSBridge.call('startApp', {
  16. // The current page is opened with the general app ID 20000067.
  17. //Therefore, other 20000067 pages are closed when startApp is called.
  18. //Actually only the current page is opened.
  19. appId: '20000067',
  20. param: {
  21. url: location.href,
  22. }
  23. }, function(result) {
  24. // noop
  25. });
  26. });
  27. });
  28. </script>
  • Open multiple pages with the same app ID:
  1. <h1>Open multiple pages with the same app ID.</h1>
  2. <a href="javascript:void(0)" class="btn multi">Start another app.</a>
  3. <script>
  4. function ready(callback) {
  5. // Call JS Bridge if it has been injected.
  6. if (window.AlipayJSBridge) {
  7. callback && callback();
  8. } else {
  9. // Listen to the injection event if it has not been injected.
  10. document.addEventListener('AlipayJSBridgeReady', callback, false);
  11. }
  12. }
  13. ready(function() {
  14. document.querySelector('.multi').addEventListener('click', function() {
  15. AlipayJSBridge.call('startApp', {
  16. appId: '90000000',
  17. param: {
  18. url: '/index.html',
  19. appClearTop: false,
  20. startMultApp: 'YES' // Note that the value is YES, not a value of the BOOL type.
  21. }
  22. }, function(result) {
  23. // noop
  24. });
  25. });
  26. });
  27. </script>

API

  1. AlipayJSBridge.call('startApp', {
  2. appId, param: {}, closeCurrentApp
  3. }, fn)

Input parameters

Parameter Data type Discription 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 an app. Its orientation level is the app, which is different from that of pushWindow .
  • By default, if the current app is already opened and startApp is called to open the app again, an operation similar to a restart is performed. That is, it is not allowed to concurrently run two instances with the same app ID.
  • To run multiple instances in one app, add the appClearTop=false&startMultApp=YES option in the param parameter.