kis vukk
Posts: 0
Joined: Tue Oct 07, 2014 12:49 pm

Detect browser/mobile platform in onDeviceReady event or somewhere else

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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Detect browser/mobile platform in onDeviceReady event or somewhere else

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.

kis vukk
Posts: 0
Joined: Tue Oct 07, 2014 12:49 pm

Detect browser/mobile platform in onDeviceReady event or somewhere else

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

kis vukk
Posts: 0
Joined: Tue Oct 07, 2014 12:49 pm

Detect browser/mobile platform in onDeviceReady event or somewhere else

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Detect browser/mobile platform in onDeviceReady event or somewhere else

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.

Return to “Issues”