Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect, that my app is running on the Ripple Emulator?

Is there a way to detect, that my application is currently running on the Ripple Emulator, instead of a real device? I want some workaround code to be ran only on the emulator.

like image 455
Vladius Avatar asked Jul 19 '14 11:07

Vladius


2 Answers

you can check if a ripple instance is aviable: if(typeof window.parent.ripple ==="undefined")

if ripple is a object, ripple is running otherweise ripple is not running! Quick and easy.

try to explain:

The target app runs in an iframe. If a ripple session has started is an object named "ripple" instantiated (at this point it does not matter what makes the object "ripple"). It's enough just to know that the object has been created. Because with this knowledge, we know that the app runs in a ripple container.

With window.parent we can query the parent node of a iframe, in this case, the ripple environment in which there is also the ripple object.

like image 83
Masood Moshref Avatar answered Oct 02 '22 03:10

Masood Moshref


You need to check the userAgent property in navigator object and check for a ripple instance on your DOM with window.parent.ripple. Ripple-Emulator is a browser userAgent. Maybe you going to add firefoxOS. :)

Hint: This is not a direct case of ripple emulator. It allows to detect browser or mobile device in 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';
}
like image 40
lin Avatar answered Oct 02 '22 04:10

lin