JSAPI

  • Since 8.0

    setTitle

    Configures the title, subtitle and option menu in title bar.

    Note:Due to App Transport Security (ATS), please use https or bases64 for image URL in iOS platform.

    Usage

    AlipayJSBridge.call('setTitle', {
      title: 'Title',
    });
    

    Example

    Various configurations for title bar

    <h1>Please press the following buttons</h1>
    <a href="javascript:void(0)" class="btn title">Configure title only</a>
    <a href="javascript:void(0)" class="btn subTitle">Configure title and subtitle</a>
    <a href="javascript:void(0)" class="btn clear">Clear title</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('.title').addEventListener('click', function() {
        AlipayJSBridge.call('setTitle', {
          title: 'Title',
        });
      });
    
      document.querySelector('.subTitle').addEventListener('click', function() {
        AlipayJSBridge.call('setTitle', {
          title: 'Title',
          subtitle: 'Subtitle',
        });
      });
    
      document.querySelector('.clear').addEventListener('click', function() {
        AlipayJSBridge.call('setTitle', {
          title: ' ',
          subtitle: ' ',
        });
      });
    });
    </script>
    

    API

    AlipayJSBridge.call('setTitle',{
      title, subtitle, image
    }, fn)
    

    Input Parameters

    NameTypeDescriptionMandatoryDefault
    titlestringText for titleN
    subtitlestringText for subtitleN
    imagestringImage URL or Base64 image. title and subtile are not effective if image is setN