关闭电报网络应用程序的方法或事件
2022-08-16
5110
我使用 React Js 制作电报网络应用。 我需要关闭电报网络应用并返回聊天的方法。 我发现信息表明 window.Telegram.WebApp 中有方法 close。但是当我控制台时,它是未定义的。而且这种方法不起作用。 甚至 console.log(window) 在电报网络应用中也没有返回任何内容
3个回答
要使Telegram对象出现在Global
窗口
对象中,您必须在
< head/>
标签中附加Telegram的脚本。您可以在
这里
。
。
twa-sdk
或
twa-bridge
。
Vladislav Kibenko
2022-12-11
问题出在 TS 中的全局参数中 需要声明
declare global {
interface Window {
Telegram: {
WebApp: {
close: () => void;
}
};
}
}
VladyslavKozlov2101
2022-08-18
<script>
Telegram.WebApp.MainButton
.setText('CLOSE WEBVIEW')
.show()
.onClick(function(){ webviewClose(); });
</script>
<div id="buttons" style="margin-top:100px;">
<button onclick="webviewClose();">Close</button>
</div>
Aref Solaimany
2023-01-05