I can’t redirect user on new page with javascript variants code:
window.location.href=url
window.location.replace (url)
window.location.assign (url)
The problem of redirect only on android, on other platforms there is no problem with going to another page.
How to fix it on android ?
View problem:
when going to any page
Addition to the post: the solution to the problem on android was using an iframe, it really helped. but now the problem is with the iframe itself on the iphone in Safari. when opening the webapp, js is not loaded. How to fix it ?
2
Answers
In order to solve the problem you have to understand it. This happens on the Android version of Telegram in WebApps. When you click on a link, it does not open in the WebApp area but in the browser.
This browser is Telegram’s internal or external browser, depending on what was indicated in Setting/Chat Setting/In-App Browser.
This bug occurs regardless of the link. So not just with your Javascript calls. A simple produces the same effect.
It seems that it comes from a bug at the level of the WebView therefore in the code of Telegram. So a change in the code of your WebApp (another Javascript function for example) will not change anything.
Solution
The solution that I tested and that works is to use an iframe. Instead of having for example index.html which has links to page1.html and page2.html, you rename your index.html to menu.html and you make an index.html page which has an iframe containing menu.html.
If you put a borderless and full-surface iframe, the user won’t notice anything.
And no need to go from menu to page1 or page2 with an iframe.src: direct Javascript links between pages that are in the iframe work perfectly, just like simple href links.
Just one point: you have to perform a window.Telegram.WebApp.ready(); in your first page so the one with the iframe (and also in the others)
Solution working at all tested platforms (Windows/Android/iOS):