如何检测我的应用程序是否在Ripple Emulator上运行?

Vla*_*ius 7 emulation hybrid ripple cordova

有没有办法检测我的应用程序当前是在Ripple Emulator上运行,而不是真正的设备?我想要一些解决方法代码只能在模拟器上运行.

Mas*_*ref 8

你可以检查一个波纹实例是否可用: if(typeof window.parent.ripple ==="undefined")

如果波纹是一个物体,波纹正在运行其他波纹没有运行!快捷方便.

试着解释一下:

目标应用在iframe中运行.如果一个ripple会话已经启动,那么一个名为"ripple"的对象被实例化(此时无论是什么使得该对象"涟漪").只知道对象已经创建就足够了.因为有了这些知识,我们知道应用程序在一个波纹容器中运行.

随着 window.parent我们可以查询一个iframe的父节点,在这种情况下,波动环境中,也有纹波对象.


lin*_*lin 1

您需要检查对象userAgent中的属性navigator并检查 DOM 上的波纹实例window.parent.ripple。Ripple-Emulator 是一个browser用户代理。也许您要添加 firefoxOS。:)

提示:这不是纹波模拟器的直接情况。它允许在 JavaScript 中检测浏览器或移动设备。

//check if the application is running on a mobile device or desktop 
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/) 
    && !window.parent.ripple) {
    app.deviceType = 'mobile';
} else {
    app.deviceType = 'browser';
}
Run Code Online (Sandbox Code Playgroud)