JSAPI

  • popWindow

    You can use popWindow to close the current page.

    Usage

    // Close the current page
    AlipayJSBridge.call('popWindow');
    

    Example

    Close the current page

    <h1>Close current page</h1>
    <a href="#" class="btn J_demo">Execute</a>
    <script>
    function ready(callback) {
      // Invoke directly if JSBridge is already injected
      if (window.AlipayJSBridge) {
        callback && callback();
      } else {
        // Otherwise listen to `AlipayJSBridgeReady` event
        document.addEventListener('AlipayJSBridgeReady', callback, false);
      }
    }
    ready(function(){
      document.querySelector('a').addEventListener('click', function() {
        AlipayJSBridge.call('popWindow');
      });
    });
    </script>
    

    Close current page and pass data to resumed page

    <h1>Click"New window",then click "Pop window" to check this demo</h1>
    <a href="#" class="btn pop">Pop window</a>
    <a href="#" class="btn new">New window</a>
    <script>
    function ready(callback) {
      // Invoke directly if JSBridge is already injected
      if (window.AlipayJSBridge) {
        callback && callback();
      } else {
         // Otherwise listen to `AlipayJSBridgeReady` event
        document.addEventListener('AlipayJSBridgeReady', callback, false);
      }
    }
    ready(function() {
      document.querySelector('.new').addEventListener('click', function() {
        AlipayJSBridge.call('pushWindow', {
          url: location.pathname
        });
      });
    
      document.querySelector('.pop').addEventListener('click', function() {
        AlipayJSBridge.call('popWindow', {
          data: {
            from: location.href,
            info: Date.now()
          }
        });
      });
    
      document.addEventListener('resume', function(event) {
        alert('Data from closed window' + JSON.stringify(event.data));
      });
    });
    </script>
    

    API

    AlipayJSBridge.call('popWindow', {
      data
    })
    

    Input Parameters

    NameTypeDescriptionMandatoryDefaultVersion
    dataobjectThe data to be received by the resumed page
    It is not possible to pass data to page with different appId
    N

    Remarks

    • closeWebview is an alias to popWindow, you can call the API with AlipayJSBridge.call('closeWebview')
    • Please refer to resume事件 for more details on how the data from popWindow is received in resumed page