Esta API establece las propiedades del botón de la esquina superior derecha de la barra de título. Para mostrarlo, también debe llamar a showOptionMenu.
Debido a las restricciones de App Transport Security (ATS) de Apple, la URL del icono debe ser un enlace HTTPS o una cadena Base64. Los enlaces HTTP se ignoran.
Uso de la API setOptionMenu
AlipayJSBridge.call('setOptionMenu', {
title : 'Button', // Choose one from title, icon, and icontype
redDot : '-1', // -1: Do not display. 0: Display a red dot. 1-99: Display a number on the red dot.
color : '#ff00ff00', // Must be an ARGB color value that starts with #.
});
Ejemplo de código
Configure distintos tipos de botones en la esquina superior derecha:
<h1>Click the buttons below to see different effects</h1>
<a href="javascript:void(0)" class="btn button">Single button</a>
<a href="javascript:void(0)" class="btn icon">Single icon</a>
<a href="javascript:void(0)" class="btn menu">Multiple menus (9.9.3)</a>
<a href="javascript:void(0)" class="btn reset">Reset</a>
<a href="javascript:void(0)" class="btn hide">Hide</a>
<a href="javascript:void(0)" class="btn show">Show</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(e) {
document.querySelector('.button').addEventListener('click', function() {
AlipayJSBridge.call('setOptionMenu', {
title : 'Button',
redDot : '5', // -1: Do not display. 0: Display a red dot. 1-99: Display a number on the red dot.
color : '#ff00ff00', // Must be an ARGB color value that starts with #.
});
AlipayJSBridge.call('showOptionMenu');
});
document.querySelector('.icon').addEventListener('click', function() {
AlipayJSBridge.call('setOptionMenu', {
icon : 'http://pic.alipayobjects.com/e/201212/1ntOVeWwtg.png',
redDot : '-1', // -1: Do not display. 0: Display a red dot. 1-99: Display a number on the red dot.
});
AlipayJSBridge.call('showOptionMenu');
});
document.querySelector('.menu').addEventListener('click', function() {
AlipayJSBridge.call('setOptionMenu', {
// The display order is from right to left.
menus: [{
icontype: 'scan',
redDot: '-1', // -1: Do not display. 0: Display a red dot. 1-99: Display a number on the red dot.
}, {
icontype: 'user',
redDot: '-1', // -1: Do not display. 0: Display a red dot. 1-99: Display a number on the red dot.
}],
override: true // If you set multiple options, specifies whether to keep the default optionMenu.
});
// Call this once to refresh the interface.
AlipayJSBridge.call('showOptionMenu');
});
document.querySelector('.reset').addEventListener('click', function() {
AlipayJSBridge.call('setOptionMenu', {
reset: true,
});
AlipayJSBridge.call('showOptionMenu');
});
document.querySelector('.show').addEventListener('click', function() {
AlipayJSBridge.call('showOptionMenu');
});
document.querySelector('.hide').addEventListener('click', function() {
AlipayJSBridge.call('hideOptionMenu');
});
document.addEventListener('optionMenu', function(e) {
alert(JSON.stringify(e.data));
}, false);
});
</script>
Descripción de la API
Si el botón no aparece como se espera después de llamar a setOptionMenu, llame a showOptionMenu.
Establezca solo una de las cuatro propiedades a continuación. El orden de prioridad es: reset > title > icontype > icon.
AlipayJSBridge.call('setTitle',{
title, icon, redDot, reset, color, override, menus, icontype
})
Parámetros de entrada
Propiedad | Tipo | Descripción | Obligatorio | Valor predeterminado |
title | string | Texto del botón derecho. | Sí | "" |
icon | string | URL del icono del botón derecho. Compatible con Base64 desde la versión 9.0. Versiones 8.3 y anteriores: iOS 40 × 40 px (sin relleno), Android 50 × 50 px (5 px de relleno transparente por lado). Versiones 8.4 y posteriores: ambas plataformas usan 40 × 40 px (sin relleno). | Sí | "" |
redDot | string | Valor del punto rojo. | No | "" |
reset | bool | Restablece la configuración predeterminada del sistema. Si reset es | Sí | false |
color | string | Valor del color del texto. | N | "#FFFFFFFF" |
override | bool | Indica si se conserva el optionMenu predeterminado al configurar varias opciones. | N | false |
menus | array | Configura varios botones. | N | [] |
preventDefault | bool | Indica si se evita la función de compartir predeterminada que abre un cuadro de diálogo. Si | N | [] |
icontype | string | Carga una imagen predefinida según el tipo especificado. Elija una opción entre Importante Los cambios de color solo son compatibles con un único optionMenu. Tipos válidos: | N | "" |
contentDesc | string | Define el texto que leerá el lector de pantalla. | N | "" |