Start other applications

更新时间:
复制 MD 格式

The startApp API opens HTML5 applications (offline packages) across packages within an mPaaS app.

Use the startApp API

AlipayJSBridge.call('startApp', {
  appId: '90000000',
  param: {
    url: '/index.html'
  }
}, function(result) {
  // noop
});

// Note: To open multiple app instances,
// place both appClearTop and startMultApp in the param object.
AlipayJSBridge.call('startApp', {
  appId: '90000000',
  param: {
    url: location.href,
    appClearTop: false,
    startMultApp: 'YES' // Note that the value is the string 'YES', not a boolean type.
  }
}, function(result) {
  // noop
});

Code examples

  • Open an application with a transparent title bar:

    <h1>Click the button to see the effect</h1>
    <a href="javascript:void(0)" class="btn dream">Open Wish Savings</a>
    <script>
    function ready(callback) {
    // If AlipayJSBridge is already injected, call the callback directly.
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // If not, listen for the injection event.
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
    }
    ready(function(){
    document.querySelector('.dream').addEventListener('click', function() {
      AlipayJSBridge.call('startApp', {
        appId: '20000981',
        param: {
          url: '/www/dream-create.html',
          // Pass startup parameters.
          canPullDown: true,
          transparentTitle: 'auto'
        }
      }, function(result) {
        // noop
      });
    });
    });
    </script>
  • Open a new application and close the current one:

    <h1>Click the button to open a new application. The current application will be closed.</h1>
    <a href="javascript:void(0)" class="btn forest">Open Ant Forest</a>
    <script>
    function ready(callback) {
    // If AlipayJSBridge is already injected, call the callback directly.
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // If not, listen for the injection event.
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
    }
    ready(function() {
    document.querySelector('.forest').addEventListener('click', function() {
      AlipayJSBridge.call('startApp', {
          appId: '60000002',
          // If you do not pass a URL, the app's default URL is used.
          param: {
            transparentTitle: 'auto'
          },
          closeCurrentApp: true
        }, function(result) {
          // noop
        });
    });
    });
    </script>
  • Open only one instance of an appId by default:

    <h1>Try to open the current page again. The current application will close and then reopen.</h1>
    <a href="javascript:void(0)" class="btn self">Open current page</a>
    <script>
    function ready(callback) {
    // If AlipayJSBridge is already injected, call the callback directly.
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // If not, listen for the injection event.
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
    }
    ready(function(){
    document.querySelector('.self').addEventListener('click', function() {
      AlipayJSBridge.call('startApp', {
        // The current page is opened by the general application 20000067.
        // Therefore, when you call startApp here, other instances of 20000067 will be closed.
        // This means only one instance of the current page remains open.
        appId: '20000067',
        param: {
          url: location.href,
        }
      }, function(result) {
        // noop
      });
    });
    });
    </script>
  • Open multiple applications with the same appId:

    <h1>Open multiple applications with the same appId</h1>
    <a href="javascript:void(0)" class="btn multi">Open another application</a>
    <script>
    function ready(callback) {
    // If AlipayJSBridge is already injected, call the callback directly.
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // If not, listen for the injection event.
      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 the string 'YES', not a boolean type.
        }
      }, function(result) {
        // noop
      });
    });
    });
    </script>

API reference

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

Input parameters

Name

Type

Description

Required

Default

Baseline

appId

string

The offline package ID.

Yes

""

-

param

dictionary

Startup parameters for the target application, such as a URL for a specific offline package page. For multi-instance configuration, add appClearTop and startMultApp (Notes).

N

The value supports string, bool, int, and double types.

-

closeCurrentApp

bool

Closes the current app before launching the new one. Useful for transitional pages.

N

-

>10.1.60

fn

function

Callback invoked on failure.

N

-

-

Error codes

Error code

Description

10

The specified appId is invalid.

11

Failed to start the application.

Notes

  • startApp opens applications at the application level, unlike pushWindow.

  • By default, calling startApp for an already-open appId restarts it. Only one instance per appId runs at a time.

  • To run multiple instances with the same appId, add appClearTop=false&startMultApp=YES to the param object.