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

2

7

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.

Emmott answered 19/7, 2014 at 11:55 Comment(1)
I have created a small JS routine, based on a chozen reply: function isOnRippleEmulator() { if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) { return false; } else { return true; } }Emmott
S
1

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';
}
Savagism answered 19/7, 2014 at 12:4 Comment(4)
Thanks a lot! That actually works. I have created a routine based on this.Emmott
Doesn't work as my Ripple userAgent is: "Mozilla/5.0 (Linux; U; Android 2.3.2; en-us; Nexus S Build/GRH78C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"Somerville
@MarekCzaplicki thanks for the downvote so. It did work fine in the past but it seems like ripple has changed. I updated my answer so it should work for you.Savagism
I believe that checking window.parent.ripple is enough to know :)Somerville
P
8

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.

Phoenicia answered 26/8, 2015 at 12:14 Comment(0)
S
1

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';
}
Savagism answered 19/7, 2014 at 12:4 Comment(4)
Thanks a lot! That actually works. I have created a routine based on this.Emmott
Doesn't work as my Ripple userAgent is: "Mozilla/5.0 (Linux; U; Android 2.3.2; en-us; Nexus S Build/GRH78C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"Somerville
@MarekCzaplicki thanks for the downvote so. It did work fine in the past but it seems like ripple has changed. I updated my answer so it should work for you.Savagism
I believe that checking window.parent.ripple is enough to know :)Somerville

© 2022 - 2024 — McMap. All rights reserved.