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.
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.
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. :)
//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';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With