Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

testing for web app or hybrid

i have an app which can either run as a hybrid or html5 app
I tried

pre
if (typeof cordova !== 'undefined') {
//we are hybrid
//do hybrid stuff
} else {
//we are an html5 app
//do html5 only stuff
}
/pre

it didn't work and always ran the html5 stuff, so I added alert(typeof cordova); into my code and I found that the corova object was 'undefined' even in my hybrid app (android apk) running on device.

Why is this, I know that i have used this technique before?

What I am trying to do is show a spash screen only if it is a html5 app bu not if it is hybrid.

My actual code is as follows:
pre
alert(typeof cordova);
console.log(typeof cordova);
if (typeof cordova !== 'undefined') {
Apperyio.navigateTo('Login', {transition:'flip', reverse:false});
} else {
setPadding();
$(window).resize(function() {
setPadding();
});
Apperyio('logo_grid').show();
setTimeout(function() {
Apperyio.navigateTo("Login", {transition:'flip', reverse:false});
}, 3000);
}/pre

If it is hybrid, it should jump straight to the login screen

logo_grid is a grid component containing the splash image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

testing for web app or hybrid

Terry,

I prefer this code....it's not perfect - but works for most situations.... and hasn't broken to date...

function fisMobile() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
}

and then instead of testing for cordova - just do if (fisMobile()){
do stuff ....
}

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

testing for web app or hybrid

Thanks Bruce, I will try this and let you know how I get on

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

testing for web app or hybrid

Hello,

Also, you can use JS function below to know, is it a native app, or browser preview:
prevar isPhoneGapApp = function () {
return (document.URL.indexOf('http://') === -1 && document.URL.indexOf('https://') === -1);
};/pre

Return to “Issues”