All Products
Search
Document Center

Close the current page

Last Updated: Mar 08, 2021

You can call this interface to close the current page.

popWindow API usage instruction

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

Code sample

  • Close the current page:
  1. <h1>Close the current page.</h1>
  2. <a href="#" class="btn J_demo">Execute</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('a').addEventListener('click', function() {
  15. AlipayJSBridge.call('popWindow');
  16. });
  17. });
  18. </script>
  • Close the current page and transfer data:
  1. <h1>Click "New window" and then "Return" to view the effect.</h1>
  2. <a href="#" class="btn pop">Return</a>
  3. <a href="#" class="btn new">New window</a>
  4. <script>
  5. function ready(callback) {
  6. // Call JS Bridge if it has been injected.
  7. if (window.AlipayJSBridge) {
  8. callback && callback();
  9. } else {
  10. // Listen to the injection event if it has not been injected.
  11. document.addEventListener('AlipayJSBridgeReady', callback, false);
  12. }
  13. }
  14. ready(function() {
  15. document.querySelector('.new').addEventListener('click', function() {
  16. AlipayJSBridge.call('pushWindow', {
  17. url: location.pathname
  18. });
  19. });
  20. document.querySelector('.pop').addEventListener('click', function() {
  21. AlipayJSBridge.call('popWindow', {
  22. data: {
  23. from: location.href,
  24. info: Date.now()
  25. }
  26. });
  27. });
  28. document.addEventListener('resume', function(event) {
  29. alert('content carried when the system returns to the previous page:' + JSON.stringify(event.data));
  30. });
  31. });
  32. </script>

API

  1. AlipayJSBridge.call('popWindow', {
  2. data
  3. })

Input parameters

Name Type Description Required Default value
data object Content transferred to the page that is about to pop up within the current app. Data cannot be transferred across apps of different IDs. N -

Precautions

For details about how data carried during popWindow is received, see Resume a page (resume event).