[英]function is not defined at file://android_asset/www/index.html in phonegap
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. 我在Phonegap上收到此典型错误,我在按钮onclick事件上调用了一个函数,但是在phonegap中的file://android_asset/www/index.html上未定义(function_name)。 Then, i write the code temp on some other page, it starts working.
然后,我在其他页面上写了代码temp,它开始工作。 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.
我正在使用phonegap-Android(在eclipse上)任何帮助将不胜感激。
<button onclick="clickIt();" data-theme="b">Login</button>
<script type="text/javascript">
function clickIt() {
//code here
}
</script>
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.
不幸的是,Android仿真器的运行速度确实很慢,因此加载文件时会发生超时,因为它会反应很慢。
Within your custom Activity file before calling super.loadUrl add the following line: 在调用super.loadUrl之前,在自定义Activity文件中添加以下行:
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
This increases the timeout for loading the webpage - this fixed the issue for me on the emulator. 这增加了加载网页的超时时间-这在模拟器上为我解决了这个问题。
Make sure to call the function only after the js file is initiated. 确保仅在启动js文件后才调用该函数。 You can make sure by callilng it inside
$(document).on
function. 您可以通过在
$(document).on
函数中调用来确保它。 first change the id of the button to login
and do as below. 首先将按钮的ID更改为
login
并执行以下操作。
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 如果您的页面ID等于“ mypage”,则将其更改为以下内容
$(document).on('pagecreate', '#mypage', function(){
$('#login').bind('click',function(){
alert('test');
});
});
Check out the live fiddle at http://jsfiddle.net/mayooresan/9pNRn/ 在http://jsfiddle.net/mayooresan/9pNRn/查看现场小提琴
I figured out the problem. 我解决了这个问题。 Actually i had an error at some function in my file and so no java script call was functioning.
实际上,我的文件中的某些功能出错,因此没有Java脚本调用起作用。 It was an error that was not found and caused other code to fail.
这是一个未发现的错误,导致其他代码失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.