如何检测我是否在 Ionic 2 的浏览器(本地开发)中 [英] How to detect if I am in browser (local development) in Ionic 2
问题描述
我想确保仅当我在设备(iOs、Android...)上时才启动 inappbrowser,但如果我在浏览器中(本地开发模式或只是具有 gulp 构建的 Web 应用程序),我只想使用 target="_blank" 链接到该页面.
I want to make sure to launch inappbrowser only if I am on devices (iOs, Android...), but if I am in browser (local development mode or just a Web App with gulp build), I want to just link to that page with target="_blank".
我正在尝试将 Ionic 2 代码重用为 Web 应用程序.因此,当我构建应用程序时,它也可以在浏览器桌面上运行.所以 platform.ready() 对我来说还不够.因为我需要知道用户是否在桌面浏览器上,我可以做一些不同的事情.
I am trying to reuse the Ionic 2 code as a Web App. So when I build the app, it will also work in browser desktop. So platform.ready() is not enough for me. As I need to know if user is on desktop browser and I can do something different.
推荐答案
来吧,你可以用下面的函数代替你的click函数.
Here you go., you can use the following function in replacement of your click function.
onClickOfButton(){
// Check If Cordova/Mobile
if (this.platform.is('cordova')) {
window.location.href = url;
}else{
window.open(url,'_blank');
}
}
这可能会有所帮助:)
这篇关于如何检测我是否在 Ionic 2 的浏览器(本地开发)中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!