I’d like to assign the value in device.platform to a variable so I can check it later in my program.
For example, if the app is running on a BlackBerry I might want to have a custom message appear.
I used the “element” example found elsewhere to make sure things were working properly (and it does). But I run into problems when I try assigning just the “device.platform” value to devicePlatform.
I’ve been fighting with this for an hour, I must be missing something fairly basic.
Can someone please show me what I’m doing wrong?
Thanks
Rob
<html>
<head>
<title>PhoneGap</title>
<meta name="viewport" content="width=device-width">
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script language="JavaScript" type="text/javascript">
// wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var element = document.getElementById('deviceProperties');
element.innerHTML = 'Device Name: ' + device.name + '<br />' +
'Device Cordova: ' + device.cordova + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Version: ' + device.version + '<br />';
//
}
</script>
</head>
<body>
<h1>Hello PhoneGap v1.9.0</h1>
<script>
var devicePlatform = device.platform;
document.write("Platform: "+devicePlatform+"<br>");
</script>
<br>
<p id="deviceProperties">Loading device properties...</p>
</body>
</html>
Try putting
into the function onDeviceReady()
This should resolve the issue.
Additionally you will probably want to define a globally scoped variable, such as ‘platform’ and then assign the device.platform to that variable in the function onDeviceReady().
Example:
UPDATE:
I think this is closer to what you are looking for