简体   繁体   English

在phonegap中的file://android_asset/www/index.html上未定义函数

[英]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.

相关问题 未捕获的ReferenceError:在文件:///android_asset/www/index.html:27上未定义show_pic - Uncaught ReferenceError: show_pic is not defined at file:///android_asset/www/index.html:27 未捕获的TypeError:对象#<Object>在file:///android_asset/www/index.html上没有方法'exec' - Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/index.html 应用程序错误是一个目录(file:///#android_asset/www/index.html) - Application Error Is a directory (file:///#android_asset/www/index.html) 与服务器的连接不成功。(file:///android_asset/www/index.html) - The connection to the server was unsuccessful.(file:///android_asset/www/index.html) Reactjs-router-dom和cordova始终直接指向file:///android_asset/www/index.html - Reactjs-router-dom and cordova always direct to file:///android_asset/www/index.html Phonegap / Android错误:未捕获ReferenceError:未在file:///android_asset/www/js/login.js:17定义url - Phonegap/Android error: Uncaught ReferenceError: url is not defined at file:///android_asset/www/js/login.js:17 Phonegap:对象xx在文件中没有方法&#39;exec&#39;:///android_asset/www/cordova.js - Phonegap: Object xx has no method 'exec' at file:///android_asset/www/cordova.js 无法在Phonegap Android中打开资产URL:file:/// android_asset / www / submit?UserName = Admin&Password = super%401234? - Unable to open asset URL: file:///android_asset/www/submit?UserName=Admin&Password=super%401234 in Phonegap Android? 您好如何为我提供帮助并解决“ file:///android_asset/www/plugin.js中未定义Cordova.exec()”错误 - hi how can help me and resolve “Cordova.exec() is not defined at file:///android_asset/www/plugin.js” error 应用中具有远程index.html的Phonegap资产下载器 - Phonegap asset downloader in app with remote index.html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM