[TIMOB-12095] Android: EvalJS does not work before a webview is loaded
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2012-12-14T00:54:11.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Allen Yeung |
Assignee | Ingo Muschenetz |
Created | 2012-12-14T00:41:52.000+0000 |
Updated | 2018-03-02T01:37:49.000+0000 |
Description
Example:
var win = Ti.UI.createWindow({
});
var webview = Ti.UI.createWebView({
url: 'test.html'
});
webview.evalJS('var phrases = {}');
webview.evalJS('phrases.breakfast = "' + L('breakfast') + '"');
webview.evalJS('phrases.nutritional_values = "' + L('nutritional_values') + '"');
win.add(webview);
win.open();
test.html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>local webview</title>
</head>
<body id="mybody" style="height:500px;background-color:#999;background-image:url(../images/bg.png)">
This is a test
<script>
Titanium.API.info("--------------------------------");
Titanium.API.info(phrases.breakfast);
</script>
</body>
</html>
Expected result:
You should see the value 'breakfast' printed out as it does in iOS
Actual result:
The value is undefined and nothing prints out.
This can't be fixed in android since we rely on the webview to run evalJS. We use loadURL('javascript:') to run the javascript code. If we do this before we actually load the webpage, it won't work since the previous javascript context will be wiped out once the actual webpage loads.
Closing based on Allen's comments.