几天前我写了一篇关于它的帖子。这是你能找到的最好的解决方案(直到 PhoneGap 发布一些东西,也许会或也许不会),它简短、简单和完美(我已经在所有可能的方式和平台上进行了检查)。
此功能将在 98% 的情况下完成工作。
/**
 * Determine whether the file loaded from PhoneGap or not
 */
function isPhoneGap() {
    return (window.cordova || window.PhoneGap || window.phonegap) 
    && /^file:\/{3}[^\/]/i.test(window.location.href) 
    && /ios|iphone|ipod|ipad|android/i.test(navigator.userAgent);
}
if ( isPhoneGap() ) {
    alert("Running on PhoneGap!");
} else {
    alert("Not running on PhoneGap!");
}
要完成另外 2% 的案例,请按照以下步骤操作(它涉及对本机代码的轻微更改):
创建一个名为__phonegap_index.html的文件,其来源为:
<!-- __phonegap_index.html -->
<script type="text/javascript">
    function isPhoneGap() {
        //the function's content is as described above
    }
    //ensure the 98% that this file is called from PhoneGap.
    //in case somebody accessed this file directly from the browser.
    if ( isPhoneGap() )
        localStorage.setItem("isPhoneGap","1");
    //and redirect to the main site file.
    window.location = "index.html";
</script>
现在,在本机上,只需将所有 PhoneGap 平台上的起始页从index.html更改为__phonegap_index.html。假设我的项目名称是example,您需要更改的文件是(对于 PhoneGap 版本 2.2.0):
- iOS -
CordovaLibApp/AppDelegate.m 
- 安卓——
src/org/apache/cordova/example/cordovaExample.java 
- 视窗 8 -
example/package.appxmanifest 
- 黑莓-
www/config.xml 
- 网络操作系统-
framework/appinfo.json 
- 八达- 
src/WebForm.cpp(第 56 行) 
- Window Phone 7 - 不知道在哪里(有人还在那个平台上开发?!)
 
最后,您可以在站点的任何位置使用它,无论它是否在 PhoneGap 上运行:
if ( localStorage.getItem("isPhoneGap") ) {
    alert("Running on PhoneGap!");
} else {
    alert("Not running on PhoneGap!");
}
希望能帮助到你。:-)