Reputation: 1028
I get this typical error on Phonegap I call a function on button onclick event, but I get (function_name) is not defined at file://android_asset/www/index.html in phonegap. Then, i write the code temp on some other page, it starts working. Again after some time the same error comesback. I can't figure out what's wrong. I am working with phonegap - Android (on eclipse) Any help would be appreciated.
<button onclick="clickIt();" data-theme="b">Login</button>
<script type="text/javascript">
function clickIt() {
//code here
}
</script>
Upvotes: 1
Views: 3487
Reputation: 67
I had the problem too. Unfortunately the Android emulator is REALLY slow so a timeout occurs while loading the files because it reacts to slow.
Within your custom Activity file before calling super.loadUrl add the following line:
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
This increases the timeout for loading the webpage - this fixed the issue for me on the emulator.
Upvotes: 1
Reputation: 1028
I figured out the problem. Actually i had an error at some function in my file and so no java script call was functioning. It was an error that was not found and caused other code to fail.
Upvotes: 0
Reputation: 17257
Make sure to call the function only after the js file is initiated. You can make sure by callilng it inside $(document).on
function. first change the id of the button to login
and do as below.
Something as below
$(document).on('pagecreate', function(){
$('#login').bind('click',function(){
alert('test');
});
});
If you have a page id equals to “mypage” change it to something as below
$(document).on('pagecreate', '#mypage', function(){
$('#login').bind('click',function(){
alert('test');
});
});
Check out the live fiddle at http://jsfiddle.net/mayooresan/9pNRn/
Upvotes: 0