你可以检查一个波纹实例是否可用:
if(typeof window.parent.ripple ==="undefined")
如果波纹是一个物体,波纹正在运行其他波纹没有运行!快捷方便.
试着解释一下:
目标应用在iframe中运行.如果一个ripple会话已经启动,那么一个名为"ripple"的对象被实例化(此时无论是什么使得该对象"涟漪").只知道对象已经创建就足够了.因为有了这些知识,我们知道应用程序在一个波纹容器中运行.
随着 window.parent我们可以查询一个iframe的父节点,在这种情况下,波动环境中,也有纹波对象.
您需要检查对象userAgent中的属性navigator并检查 DOM 上的波纹实例window.parent.ripple。Ripple-Emulator 是一个browser用户代理。也许您要添加 firefoxOS。:)
//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)
| 归档时间: |
|
| 查看次数: |
1382 次 |
| 最近记录: |