如何检测我是否在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 App。所以当我构建应用程序时,它也可以在浏览器桌面上运行。所以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.
推荐答案
在这里,您可以使用以下功能代替您的点击功能。
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屋!