Page 1 of 1

Detect browser/mobile platform in onDeviceReady event or somewhere else

Posted: Thu Oct 16, 2014 8:25 am
by kis vukk

Hi
Try to detect Browser/Mobile platform in onDeviceReady event

I used this code in a js file

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.dtype = device.platform;
}

And startScreen Load JS console.log(window.dtype) but is always undefined
I thought it's only works on real mobile devices.
Changed code to this one

if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener("deviceready", onDeviceReady, false);
window.dtype = "app";
} else {
onDeviceReady(); //this is the browser
window.dtype = "browser";
}

dtype undefined too, tried code in startScreen Device Ready event JS, same result, in Load JS shows dtype undefined.

How can detect browser/device platform?


Detect browser/mobile platform in onDeviceReady event or somewhere else

Posted: Thu Oct 16, 2014 9:16 am
by Kateryna Grynko

Hi Kis,

Please run this code on page Load event or add it a a JS file:
preif (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {

document.addEventListener("deviceready", onDeviceReady, false);

window.dtype = "app";

} else {

onDeviceReady(); //this is the browser

window.dtype = "browser";

}/pre
Add codeconsole.log/code on page Load or Page Show event and check a value of

codewindow.dtype/code.


Detect browser/mobile platform in onDeviceReady event or somewhere else

Posted: Wed Oct 22, 2014 9:15 am
by kis vukk

Hi

Got this error message on console

Uncaught ReferenceError: onDeviceReady is not defined (anonymous function)

Try both way: in startscreen load js and a single js file too


Detect browser/mobile platform in onDeviceReady event or somewhere else

Posted: Wed Oct 22, 2014 9:39 am
by kis vukk

Ok, I don't need deviceready, it's does not work in browser
If i rem this two line get the answer


Detect browser/mobile platform in onDeviceReady event or somewhere else

Posted: Wed Oct 22, 2014 11:23 am
by Evgene Karachevtsev

Hello Kis,

This code
preif (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener("deviceready", onDeviceReady, false);
window.dtype = "app";
} else {
onDeviceReady(); //this is the browser
window.dtype = "browser";
}/pre
should be linked to the event 'load' of your page or to be situated in the js file.
console.log you should hang on load or page show event and look the value of window.dtype.