【发布时间】:2022-12-12 02:00:57
【问题描述】:
我有一个站点,其中仅包含一个图像。当有人点击它时,图像开始下载到用户的计算机。最近,我试图将它作为 Telegram Web App 启动,但碰巧出现了问题。当我在我的电脑上(作为 TG WebApp)点击图像时,一切正常,但是当我在我的手机(sumsung a51)(作为 TG WebApp)上点击它时,没有任何反应。 我网站的代码: HTML(仅正文):
<div class="wrapper">
<img class="image" src="pathtoimg" alt="img"></img>
</div>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="./index.js"></script>
JS(索引.js):
async function toDataURL(url) {
const blob = await fetch(url).then(res => res.blob());
return URL.createObjectURL(blob);
}
async function downloadFile(src, filename) {
const a = document.createElement("a");
a.href = await toDataURL(src);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function main() {
const image = document.querySelector(".image")
if (image) {
image.addEventListener("click", (e) => {
downloadFile(image.src, "image.png")
})
}
}
main()
感谢所有试图帮助我的人,我很珍惜
【问题讨论】:
标签: javascript html css telegram telegram-bot