You can use pushWindow
to open a new page, with transition animation provided in iOS platform. Please note that you cannot use this API to open pages from other applications (Please use startApp
API instead).
Please use location.href
for opening deep-linking page with custom scheme instead of using pushWindow
.
The behaviour of pushWindow
is similar to opening new tab in browser, pushWindow
creates a new instance of page, and keep the state of pervious page in stack, allowing the Javascript in old page continue running in the background.
// Open taobao homepage, use taobao homepage title as page title and remove option menu
AlipayJSBridge.call('pushWindow', {
url: 'https://m.taobao.com/',
param: {
readTitle: true,
showOptionMenu: false
}
});
<h1>Open taobao homepage</h1>
<a 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() {
// Open taobao homepage, use taobao homepage title as page title and remove option menu
AlipayJSBridge.call('pushWindow', {
url: 'https://m.taobao.com/',
param: {
readTitle: true,
showOptionMenu: false
}
});
});
});
</script>
<h1>Open desired app</h1>
<a 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('pushWindow', {
url: 'alipays://platformapi/startapp?appId=60000002',
});
});
});
</script>
<h1>Open taobao homepage</h1>
<a 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('pushWindow', {
url: 'https://m.taobao.com',
param: {
transparentTitle: 'auto'
}
});
});
});
</script>
AlipayJSBridge.call('pushWindow', {
url, param
})
Name | Type | Description | Mandatory | Default | Version |
---|---|---|---|---|---|
url | string | The page URL to be opened | Y | ||
param | dictionary | Supported key/value pairs defined in the parameter table below | N | {} |
Name | Type | Description | Default | Version |
---|---|---|---|---|
defaultTitle | string | Default tile, displayed when page is being loaded | ‘’ | |
showLoading | bool | Whether or not to display global loading spinner | false | |
readTitle | bool | Whether or not to use webpage title in title bar | true | |
pullRefresh | bool | Whether or not to support pull to refresh | false | since 8.2 |
toolbarMenu | string | An JSON string that specifies additional menu items. e.g., {“menus”:[{“name”:”Foo”,”icon”:”H5Service.bundle/h5_popovermenu_share”,”action”:”hello”},{“name”:”Bar”,”icon”:”H5Service.bundle/h5_popovermenu_abuse”,”action”:”world”}]} | ‘’ | since 8.2 |
canPullDown | bool | Whether or not to support pull down Obsoleted since 9.9.5, Use ‘allowsBounceVertical’instead | true | android since 8.3 ios since 8.4, |
allowsBounceVertical | bool | Whether or not allow vertical bounce | true | since 9.9.3 |
bounceTopColor | int | The edge color of bounce top(Decimal,e.g., bc=16775138) | Same as 9.9.3 when undefined | since 9.9.3 |
bounceBottomColor | int | The edge color of bounce bottom(Decimal,e.g., bc=16775138) | Same as 9.9.3 when undefined | since 9.9.3(only IOS) |
showTitleLoading | bool | Whether or not to show the title loading spinner | false | since 8.6 |
preRpc | string | The Start-up parameter for RPC request (in utf-8 encoding), please refer to the RPC API for more details | since 9.3 | |
delayRender | bool | Whether or not to delay rendering. Note: this parameter is only effective if this feature is enabled in remote configuration | false | since 9.3.1(only Android) |
transparentTitle | string | Mutually exclusive with titleBarColor always/auto: If set to always, the title bar is alawys transparent no matter whether the page is being scrolled up or down. If set to auto, transparency is increased when page is being scrolled down until full transparent when scrollTop == 80pt. Transparency is decreased when page is being scrolled up until full opaque. If transparency transition is not required, please set transparentTitle to none | ‘’ | since 9.5.1 |
titleBarColor | int | Mutually exclusive with transparentTitle (Decimal, e.g., bc=16775138) | ||
scrollDistance | int | Only effective if transparentTitle is set to auto The distance to scroll in order to reach transparency == 0.96 | iOS(80) | since 9.9 |
startMultApp | bool | Whether or not to start application with the same appID | false | since 9.9 |
titleImage | string | The URL to title image. Please use a 3x PNG image, only effective in the current ViewController, please put the image in the global offline package for better user experience | ‘’ | since 9.9.5 |
closeCurrentWindow | bool | Close the current window when opening up new page | false | since 9.9.2 |
animationType | string | Type of animation, available options are none and push . Note: Not available in Android | ‘push’ | since 10.0.15 |
The values of some of the pushWindow
Parameters from the current H5 page window are automatically transferred to the new opening page, please refer to the following table for transferrable parameters
Name | Transferrable to new page | Remarks |
---|---|---|
url | Y | |
defaultTitle | Y | |
backBehavior | Y | pop unless specified by user |
showLoading | Y | |
readTitle | Y | |
pullRefresh | Y | |
toolbarMenu | Y | |
showProgress | Y | |
defaultSubtitle | Y | |
backgroundColor | Y | |
canPullDown | Y | |
showOptionMenu | Y | |
showTitleLoading | Y | |
showDomain | Y |
Beginners are usually confused by
pushWindow
andlocation.href
, and having doubts such as whyresume
events are not being triggered properly. Actually the concept is quite simple if you understand the following key points.
pushWindow
action is similar to opening a page in a new Tab and deactivating the current Tablocation.href
action is like loading a webpage inside the currently opened Tabresume
event is triggered in this casepushWindow
to open new page, opening too many pages may consume lots of memory and thus make application performance poor. It is recommended to keep the number of opened pages to 5, otherwise it will be a bad user experience with potential crashespushWindow
API will close the existing page that matches the passed appId
and open create a new page with the same appId
window.location.href
, you can use closeCurrentWindow
parameter to close the current window and open a new one. However, there is a technical limitation in iOS platform, such that the newly opened window cannot be closed via exitApp
or startApp+closeCurrentApp
. It is recommended to pushWindow+closeCurrentWindow
in this scenario