skip to Main Content

I found that the method Expand of window.Telegram.WebApp object isn’t working in the Telegram client for Windows and IOS on computers and tablets.
How to increase the size of Web Apps frame for those devices?

3

Answers


  1. function buttonOn(){
         // do something on btn click
    }
    
    let main_page = document.querySelector('#main_page');
    
    
    if  (main_page){
        window.Telegram.WebApp.expand() //expand window after page loading
    
        window.Telegram.WebApp.MainButton.onClick(buttonOn) //set func on main button click
        window.Telegram.WebApp.MainButton.setParams({'text': 'Корзина'}) // set byn params
        window.Telegram.WebApp.MainButton.show() //show telegram btn
    }
    

    Other button events

    Login or Signup to reply.
  2. Remove the line from the function:

    window.Telegram.WebApp.expand() //expand window after page loading
    

    And call it in the beginning/at the top of your main javascript code. (The code that will start running once the user has clicked on the button)

    Also, you can make your code a lot shorter by putting window.Telegram.WebApp in a variable like:

    const tele = window.Telegram.WebApp; //Initializes the TELEGRAM BOT and
      //Gets the user's Telegram ID from the Telegram API
    
    tele.expand(); //Expands the app on the users' phone to 100% height
    
    Login or Signup to reply.
  3. The reason is, probably, you are a bit incorrect in understanding what "expansion" is. This term could only be applied to mobile devices with OS such as Android or iOS. Web App is displayed there in such native component as BottomSheet with inserted WebView containing your web application. Initially, in mobile devices, application is being opened minimized (not expanded). To make it use maximum allowed height of screen, you could call expand() method. It must work through window.Telegram.WebApp.expand().

    In desktop or web versions of Telegram, Web App is displayed in separate component which is not allowed to change its size.

    You could probably find more useful information about viewport and expansion here, or use alternative libraries, such as twa-bridge or twa-sdk

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search