在移动浏览器或PhoneGap应用程序之间检测 [英] Detect between a mobile browser or a PhoneGap application

查看:108
本文介绍了在移动浏览器或PhoneGap应用程序之间检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以检测用户是否使用JavaScript通过浏览器或应用程序进行访问?



我通过网页和PhoneGap应用程序为几个移动操作系统开发混合应用程序,目标是:


  1. 使用与部署目标无关的相同代码

  2. 仅当用户代理是应用程序时添加PhoneGap.js文件


解决方案

您可以检查当前网址是否包含 http 协议。

  var app = document.URL.indexOf('http://')=== -1& & document.URL.indexOf('https://')=== -1; 
if(app){
// PhoneGap应用程序
} else {
//网页
}
pre>

Is it possible to detect if the user is accessing through the browser or application using JavaScript?

I'm developing a hybrid application to several mobile OS through a web page and a PhoneGap application and the goal would be to:

  1. Use the same code independently of the deployment target
  2. Add PhoneGap.js file only when the user agent is an application

解决方案

You could check if the current URL contains http protocol.

var app = document.URL.indexOf( 'http://' ) === -1 && document.URL.indexOf( 'https://' ) === -1;
if ( app ) {
    // PhoneGap application
} else {
    // Web page
}

这篇关于在移动浏览器或PhoneGap应用程序之间检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆