Need double link to phonegap.js for ondeviceready to register

26 views
Skip to first unread message

tverburg

unread,
Jun 23, 2011, 6:10:13 AM6/23/11
to phonegap
Hi everyone,

I'm new to Phonegap and have been struugling with a few strange things
before I can really get to work.

I started with trying to add a menubutton function to a project but I
kept getting stuck. (maybe also because I read that the menubutton
functionality was no longer in phonegap 0.9.5.1. Does anyone know why
that is? I tried re adding it myself)

But the biggest problem was that I can't get "deviceready" to be
called. For some reason phonegap.js was not being linked to my html
(that is what I figured anyway). After a lot of searching on the
internet and copypasting bits of script I suddenly got it working but
in a very strange way. I have linked phonegap.js twice in a bit
different way and this is the only way that works. I need to have both
these lines in my <head> for deviceready to be called:
<script type="text/javascript" charset="utf-8" src="./phonegap.js"></
script>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></
script>
If I remove either of them nothing happens anymore.

I'm sure I'm overlooking something extremely obvious but I cant see it
(stared at it to long I guess ;) )

Does anyone have any idea what i'm doing wrong here? I appreciate the
effort. This is my full html:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>PhoneGap Device Ready Example</title>

<script type="text/javascript" charset="utf-8" src="./phonegap.js"></
script>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></
script>

<script type="text/javascript" charset="utf-8">

// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap.js has
not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady,
false);
alert('html loaded');
}

// PhoneGap is loaded and it is now safe to make calls PhoneGap
methods
function onDeviceReady() {
// Register the event listener
document.addEventListener("menubutton", onMenuKeyDown,
false);
alert('deviceready loaded');
}

// Handle the menu button
function onMenuKeyDown() {
//alert('menu key pressed');
}

</script>
</head>
<body onload="onLoad()">
</body>
</html>

thanks in advance,
Thijs

Shazron Abdullah

unread,
Jun 23, 2011, 2:59:20 PM6/23/11
to phon...@googlegroups.com
Just checking, did you use the Android phonegap.0.9.5.1.js in the downloaded package?
I assume you renamed it in your code below to phonegap.js

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

tverburg

unread,
Jun 28, 2011, 3:22:42 PM6/28/11
to phonegap
Hi,

Yes I did. I also tried an older and a modified version. A coworker of
mine opted that the page could have loaded faster than the script
causing the phonegap link to not register. A double declaration might
have given it the extra time it needed.

I'll post back if I can verify this

Thnx for the reply




On 23 jun, 14:59, Shazron Abdullah <shazron.abdul...@nitobi.com>
wrote:
Reply all
Reply to author
Forward
0 new messages