window.open 或 window.location.replace 错误处理
const openInstallPage = () => {
const md = new MobileDetect(navigator.userAgent);
if (md.is("iPhone")) {
window.open(
"https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202"
);
} else if (md.os() || md.mobile()) {
try {
window.open(
"https://metamask.app.link/dapp/emirpreview.vercel.app" //deeplink, this url will try to open metamask mobile app. If it cant, i want to redirect user to install page.
);
} catch (err) {
window.open("https://play.google.com/store/apps/details?id=io.metamask");
}
} else {
window.open(
"https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"
);
}
};
当有人在移动设备上单击我的按钮时,我想将用户重定向到元掩码应用程序(如果已安装)。如果不是,我想将用户重定向到元掩码安装页面。
我该如何处理这个问题?尝试 catch 方法根本不起作用...我做错了什么吗?
注意:我想在移动设备上执行此操作,因此我使用 npm 中的 mobile-deteck 包。
const openInstallPage = () => {
const md = new MobileDetect(navigator.userAgent);
if (md.is("iPhone")) {
window.open(
"https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202"
);
} else if (md.os() || md.mobile()) {
try {
window.open(
"https://metamask.app.link/dapp/emirpreview.vercel.app" //deeplink, this url will try to open metamask mobile app. If it cant, i want to redirect user to install page.
);
} catch (err) {
window.open("https://play.google.com/store/apps/details?id=io.metamask");
}
} else {
window.open(
"https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"
);
}
};
When someone click my button on mobile, i want to redirect user to the metamask app if its installed. If it's not i want to redirect user to metamask install page.
How can i handle this? Try catch methods are not working at all... Am i doing something wrong?
Note: i want to do this things on mobile so im using mobile-deteck package from npm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论