All Products
Search
Document Center

Mobile Platform as a Service:Close multiple pages

Last Updated:Jan 28, 2026

This interface lets you navigate back through multiple pages at once.

Note

popTo only works for pages within the current app instance. It does not support navigation across different app IDs.

Using the popTo interface

// Close the currently open page
AlipayJSBridge.call('popTo', {
  index: -1
});

Code examples

  • Close the current page and pass data:

    <h1>Click "Execute" to close the current page and return data</h1>
    <a href="#" class="btn J_demo">Execute</a>
    <script>
    function ready(callback) {
    // If jsbridge is already injected, call it directly.
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // If not, listen for the injection event.
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
    }
    ready(function(){
    document.querySelector('.J_demo').addEventListener('click', function() {
      // The page that appears next receives the passed data object through the resume event.
      AlipayJSBridge.call('popTo', {
        index: -1, // Go back to the previous page. An error occurs if no previous page exists.
        data: { // Note: data is a dictionary, not an array.
          from: location.href,
          info: Date.now()
        }
      }, function(e) { // Add a callback, because popTo might fail. An error occurs if the current page is the only one open.
        alert(JSON.stringify(e));
      });
    });
    });
    </script>
  • Return to a page that matches a regular expression using urlPattern:

    <h1>Return to a URL that matches a rule</h1>
    <h3></h3>
    <a href="javascript:void(0)" class="btn J_new_window">Open current page in a new window</a>
    <a href="javascript:void(0)" class="btn J_demo">Back</a>
    <script>
    var query = getQuery();
    var depth = (+query.depth) || 0;
    document.querySelector('h3').innerHTML = 'Current page depth: ' + depth;
    function ready(callback) {
    // If jsbridge is already injected, call it directly.
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // If not, listen for the injection event.
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
    }
    ready(function(){
    document.querySelector('.J_demo').addEventListener('click', function() {
      AlipayJSBridge.call('popTo', {
        urlPattern: 'pop-to-url-pattern.html',
      }, function(e) {
        alert(JSON.stringify(e));
      });
    });
    
    document.querySelector('.J_new_window').addEventListener('click', function() {
      AlipayJSBridge.call('pushWindow', {
        url: location.pathname + '?depth=' + (1+depth),
      });
    });
    });
    </script>

API reference

Important
  • Use popTo for multi-step scenarios, such as navigating back after a user completes their profile or selects a three-level address.

  • When you use urlPattern, popTo navigates to the page that is furthest from the current page, which is the bottom of the stack. The operation does not check if the URL of the current page matches the pattern.

  • For more information about how to receive data passed with popTo, see Page resume (resume event).

AlipayJSBridge.call('popTo',{
  index, urlPattern
}, fn)

The index and urlPattern demand modes are mutually exclusive.

Input parameters

Name

Type

Description

Required

Default

index

int

The index of the target page in the session page stack. If the value is less than zero, it is added to the index of the current page.

Y

-

urlPattern

string

A URL matching expression for the target page. A match is successful if the page URL contains the urlPattern string.

Y

“”

fn

function

The callback function is executed if the operation fails. The callback might not be invoked if the operation succeeds.

N

-

Output parameters

Name

Type

Description

result

undefined

The callback might not be invoked if the operation succeeds. Do not use the result parameter.

Error codes

Error code

Description

10

Missing parameters. Invalid index. No match for urlPattern.