Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Contributor
Posts: 6
Registered: ‎02-19-2013
My Device: BlackBerry 9320
My Carrier: BlackBerry
Accepted Solution

onload="init()" or any menu event is not triggering in Cordova BlackBerry mobile application

[ Edited ]

Hi,

 

Im using BlackBerry 9320 device. I developed an application using cordova-phonegap 2.2.0. In this the html body onload event is not triggering and menu is not firing. I have included the cordova.js in the html file.

 

Please help meSmiley Sad

 

This is my code...

 

<!doctype html>
<html>
<head>
<title>TechOps-Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/jquery.mobile.css" />
<link rel="stylesheet" href="css/jquery.mobile.theme" />
<link rel="stylesheet" href="css/site.css" />
<style>
div#menu {
width: 100%;
background-color: Black;
position:absolute;
bottom: 0;
color:white;
display:none;
}
</style>

<style>
#loadImg{position:absolute;z-index:999;display:none;left:20%;margin-left:20%;}
#loadImg div{display:table-cell;background:#fff;text-align:center;vertical-align:middle;}
</style>
<script src="js/knockout.js"></script>
<script src="js/knockout.mapping.js"></script>
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile.js"></script>
<script src="js/fly.js"></script>
<script type="text/javascript" src="js/cordova.js"></script>

<script>
var username, password;



if(localStorage.getItem('username') && localStorage.getItem('password')) {
// alert('h');

//document.login_form.username= localStorage.getItem('username');
// document.login_form.password = localStorage.getItem('password');
document.getElementById('loadImg').style.display='block';
window.username = localStorage.getItem('username');
window.password = localStorage.getItem('password');

// alert('i');

$.ajax({

type: 'HEAD',
url: <my url>',
crossDomain: true,
data&colon; { username: encodeURIComponent(username), password: encodeURIComponent(password) },

success: function(responseData, textStatus, jqXHR)
{

console.log(responseData);console.log('!!!!!!!!!!!!!!'+textStatus);console.log('!!!!!!!!!!!!'+jqXHR);
document.getElementById('loadImg').style.display='none';
window.location.href ="index.html";

},
error: function (responseData, textStatus, errorThrown)
{

console.warn(responseData, textStatus, errorThrown);
document.getElementById('loadImg').style.display='none';
alert('Login Failed. Kindly re-login / Contact Tech Tools Team');

if(localStorage.getItem('username') && localStorage.getItem('password')) {
localStorage.removeItem('username');
localStorage.removeItem('password');
} else {
sessionStorage.removeItem('username');
sessionStorage.removeItem('password');
}
}
});

}



var menuOpen = false;
var menuDiv = "";
function hi()
{
console.log('!!!!!!!!!!!!set!!!!!!!!!!!!!!!!');
window.location.href='index.html';
}
function nav()
{
console.log('@@@@@@@@@@@@@@@@@');
navigator.app.exitApp(this);
}
function hit()
{
console.log('$$$$$$$$$$$$$');
if(!username && !password)
{alert('Please enter username and password');}else{
window.location.href='indexS.html';}
}
function checkConnection() {

var networkState = navigator.network.connection.type;

var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
if(
states[Connection.NONE] == 'No Internet Connectivity'){
alert('Connection type: ' + states[networkState]);
}


}
function init() {
document.addEventListener("deviceready", startup, false);
}
function onOffline()
{
alert('No Internet Connectivity Found. Exiting App!');
navigator.app.exitApp(this);
}
function startup() {
//checkConnection();
document.addEventListener("resume", onResume, false);
document.addEventListener("offline", onOffline, false);
checkConnection();
console.log("Business time...");
menuDiv = document.querySelector("#menu");

document.addEventListener("menubutton", doMenu, false);
}

function onResume() {
setTimeout(function() {
// TODO: do your thing!
window.location.reload(true);
}, 0);
}

function doMenu() {
console.log("The menu was clicked...");
if(menuOpen) {
console.log("close the menu");
menuDiv.style.display="none";
menuOpen = false;
} else {
console.log("open the menu");
menuDiv.style.display="block";
menuOpen = true;
}

}

function authenticate() {

document.getElementById('loadImg').style.display='block';
window.username = document.login_form.username.value;
window.password = document.login_form.password.value;
var success = false, isAuthenticated = false;

// Validation
if(!username && !password)
return;

// Authenticate



$.ajax({

type: 'HEAD',
url: '<my url>',
crossDomain: true,
data&colon; { username: encodeURIComponent(username), password: encodeURIComponent(password) },

success: function(responseData, textStatus, jqXHR)
{
document.getElementById('loadImg').style.display='none';
if(document.login_form.rememberCredentials.checked) {
localStorage.setItem('username', username);
localStorage.setItem('password', password);

} else {
sessionStorage.setItem('username', username);
sessionStorage.setItem('password', password);

}

console.log(responseData);
console.log('!!!!!!!!!!!!!!'+textStatus);console.log('!!!!!!!!!!!!'+jqXHR);
window.location.href ="index.html";
},
error: function (responseData, textStatus, errorThrown)
{
document.getElementById('loadImg').style.display='none';
console.warn(responseData, textStatus, errorThrown);

alert('Login Failed. Kindly re-login');
document.login_form.username.value="";
document.login_form.password.value="";
if(localStorage.getItem('username') && localStorage.getItem('password')) {
localStorage.removeItem('username');
localStorage.removeItem('password');
} else {
sessionStorage.removeItem('username');
sessionStorage.removeItem('password');
}
return;
}
});

if(document.login_form.rememberCredentials.checked) {
localStorage.setItem('username', username);
localStorage.setItem('password', password);
} else {
sessionStorage.setItem('username', username);
sessionStorage.setItem('password', password);
}


}

 

</script>


</head>
<body onload="init()">

<!-- Login Page -->

<div data-role="page" id="login">
<div data-role="header">
<h1>TechOps</h1>
</div>
<form name="login_form" action="" method="post">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username" class="ui-hidden-accessible">Associate ID</label>
<input id="username" type="text" name="username" placeholder="Associate ID" />
</div>

<center> <img id="loadImg" style="display:none;" src="css/images/ajax-loader.gif" /></center>


<div data-role="fieldcontain" class="ui-hide-label">
<label for="password" class="ui-hidden-accessible">Password</label>
<input id="password" type="password" name="password" placeholder="Password" />
</div>
<label><input type="checkbox" name="rememberCredentials" />Log In Automatically</label>
<a href="javascript&colon;authenticate();" data-theme="b" data-role="button">Submit</a>

</form>

<div id="menu" ><center>
<table style="height:50px;">
<tr>
<td >
<button type="button" style="padding: 0;

background: none;font-family: Palatino;color:white;font-size: 25px;" onclick="nav()">Exit</button>
</td>

</tr></table></center>
</div>
</div>

</body>
</html>

New Contributor
Posts: 6
Registered: ‎02-19-2013
My Device: BlackBerry 9320
My Carrier: BlackBerry

Re: onload="init()" or any menu event is not triggering in Cordova BlackBerry mobile application

It's resolved. Could able to call the function.