Webview evalJS return null in Android 4.2.2
On 3 October 2013 in TechI have a webview that points to external URL
var webview = Ti.UI.createWebView({ url: 'http://example.com/test.html' });
In test.html I have a global variable
<script type="text/javascript"> var myvar = JSON.stringify({ status: true }); </script>
On webview onload event, evalJS('myvar')
return null, and inside log message got “Timeout waiting to evaluate JS”. After a few days try & error, test and compare, finally I found the culprit is within tiapp.xml file.
My tiapp.xml has a customized <android>
section
<android xmlns:android="http://schemas.android.com/apk/res/android"> <tool-api-level>17</tool-api-level> <manifest android:installLocation="auto" android:versionCode="1" android:versionName="1.0.0"> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/> <application> <activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/> </application> </manifest> <services> <service type="standard" url="lib/service/clear.js"/> </services> </android>
It turns out that <uses-sdk>
part is the one causes this bug. Removing the line <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
fix this bug and I can retrieve myvar values using evalJS() again.
Related posts:
-
Ti.Network.registerForPushNotifications no response
-
Restart ADB
-
Lazyloading JS modules in Titanium app
-
ActionBarImplBase can only be used with a compatible window decor layout
-
Update iOS Titanium module SDK version
-
Setup Titanium Studio environment for developing Titanium module (Android) on Windows
-
Titanium Android keystore
-
Designing web page for Android webview
-
Android BOOT_COMPLETED handler module
-
Google Play Store updated UI for Gingerbread
Filed under Tech with tags Android, Javascript, Titanium Mobile, WebView
I see you share interesting content here, you can earn some additional money, your blog has
big potential, for the monetizing method, just search in google – K2 advices
how to monetize a website
Thanks for sharing, not working with me, any ideas?