You can use the pushWindow method to open a new page within the same offline package. This method includes a default system transition animation. To open a page in a different offline application, use the startApp API.
The difference between the pushWindow method and the frontend location.href property is similar to opening a new tab in a desktop browser. When you use pushWindow, the original page is pushed to the background, but its state is preserved and its JavaScript continues to run.
How to use the pushWindow API
// Open the Taobao homepage, automatically read the title, and remove the right menu button.
AlipayJSBridge.call('pushWindow', {
url: 'https://m.taobao.com/', // The URL of the page to open.
// Configuration parameters for the new page.
param: {
readTitle: true, // Automatically read the title.
showOptionMenu: false // Hide the right menu.
},
// Optional. Used to pass parameters to the new page.
// In the new page, use AlipayJSBridge.startupParams to get passData.
passData: {
key1: "key1Value",
key2: "key2Value"
}
});For Android applications, place the parameters in
param: {}.For iOS applications, place the parameters in
passData: {}.
Code examples
Open the Taobao homepage and remove the right-side menu.
<h1>Open Taobao Homepage</h1> <a 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 injected, listen for the injection event. document.addEventListener('AlipayJSBridgeReady', callback, false); } } ready(function(){ document.querySelector('a').addEventListener('click', function() { // Open the Taobao homepage, automatically read the title, and remove the right menu. AlipayJSBridge.call('pushWindow', { url: 'https://m.taobao.com/', param: { readTitle: true, showOptionMenu: false } }); }); }); </script>Set a transparent title bar when you open the page.
<h1>Open Taobao Homepage</h1> <a 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 injected, listen for the injection event. document.addEventListener('AlipayJSBridgeReady', callback, false); } } ready(function() { document.querySelector('a').addEventListener('click', function() { AlipayJSBridge.call('pushWindow', { url: 'https://m.taobao.com', param: { transparentTitle: 'auto' } }); }); }); </script>
API reference
The pushWindow method does not close existing pages when it opens a URL. To avoid performance issues, monitor the number of open pages.
Do not exceed five levels of pushWindow calls in the same application. Exceeding this limit can negatively affect the user experience and may cause the application to crash.
AlipayJSBridge.call('pushWindow', {
url, param, passData
})Input parameters
Name | Type | Description | Required | Default |
url | string | The URL to open. | Yes | "" |
param | dictionary | For supported key-value pairs, see the table below. | N | {} |
passData (For iOS only) | dictionary | The parameters to pass. Use | N | {} |
param parameter details
Name | Type | Description | Default |
defaultTitle | string | The default title displayed on the title bar before the page loads for the first time. | "" |
showLoading | bool | Specifies whether to display a global loading spinner before the page loads. | false |
readTitle | bool | Specifies whether to read the webpage title and display it on the titleBar. | true |
pullRefresh | bool | Specifies whether to enable pull-to-refresh. This can only be set to true for local files. | false |
allowsBounceVertical | bool | Specifies whether the page can be pulled vertically beyond its content. On Android, only pull-down is supported, which reveals the background or domain name. This can only be set to false for local files and pages under .alipay.com or | true |
bounceTopColor | int | The color of the top gap when the page is pulled down beyond its content. Use a decimal value. For example, `bc=16775138`. | - |
showTitleLoading | bool | Specifies whether to display a small loading spinner to the left of the title on the titleBar. | false |
transparentTitle | string | Cannot be used with 1. 2. 3. | - |
titleBarColor | int | The custom background color for the title bar. Use a decimal value. For example, `bc=16775138`. Important Cannot be used with | - |
scrollDistance | int | When | 80 (iOS) |
titleImage | string | The URL of the image to use for the title. Upload a 3x PNG image. This parameter only affects the current view controller (VC). | "" |
closeCurrentWindow | bool | Closes the current window when opening the new one. | false |
closeAllWindow | bool | Closes all windows of the current app when opening the new one. | false |
animationType | string | The animation type. The default is "push". Available enumerations are "none" and "push". Important This parameter is not implemented on Android. No animation is shown. | "" |
Default inheritance of pushWindow parameters
Name | Inherited | Notes |
url | Yes | - |
defaultTitle | Yes | - |
backBehavior | Yes | Uses the user-specified value. If not specified, the default is `pop`. |
showLoading | Yes | - |
readTitle | Yes | - |
pullRefresh | Yes | - |
toolbarMenu | Yes | - |
showProgress | Yes | - |
defaultSubtitle | Yes | - |
backgroundColor | Yes | - |
canPullDown | Yes | - |
showOptionMenu | Yes | - |
showTitleLoading | Yes. | - |
showDomain | Yes | - |
Differences between pushWindow and location.href
The key differences between pushWindow and location.href are as follows:
You can think of the Nebula container as a desktop browser.
A window is like a browser tab. The location.href property performs standard page navigation within that tab.
The pushWindow method opens a new tab. It pushes the previous page to the background, displays the new page in the foreground, and preserves the state of the background page.
In contrast, location.href navigates to a new page within the same tab, replacing the current page.
When a page that was opened with pushWindow is closed (popped), the previous window is restored and displayed. This action triggers a
resumeevent.