[TIMOB-18788] Android: evalJS("document.height") returns undefined on Android 4.4.4
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Not Our Bug |
| Resolution Date | 2015-06-16T02:15:13.000+0000 |
| Affected Version/s | Release 3.5.1 |
| Fix Version/s | Release 4.1.0 |
| Components | Android |
| Labels | android, evaljs, webview |
| Reporter | David IAV |
| Assignee | Ashraf Abu |
| Created | 2014-07-22T12:09:10.000+0000 |
| Updated | 2015-06-19T22:10:55.000+0000 |
Description
Quering a webview to get the height of the content using webview.evalJS("document.height") works fine on Android 4.4.2 (tested on HTC One) and lower devices, but Android 4.4.4 devices (tested on the Nexus 5 and 7) returns undefined instead of the height of the content. Sample code:
{noformat}
body.addEventListener('load', function(e) {
var h = body.evalJS("document.height");
Ti.API.info("Content height: " + h); // returns height on < 4.4.2, undefined on 4.4.4
}
{noformat}
Ok. No problem. Test case is following:
var win = Ti.UI.createWindow(); var webview = Ti.UI.createWebView({ url: 'http://www.google.com' }); win.add(webview); webview.addEventListener('load',function(e) { var l = webview.evalJS("document.height"); Ti.API.info("Context Length " + l); }); win.open();Hi, I had the very same issue, but as a fix, instead of relying on document.height I now use the following which seems to work perfectly:
Kaivar _height = _html_view.evalJS("Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);"); Hope this helps!I think [~kaiiserni] is correct. I'm just looking around and it seems like for Mozilla [https://developer.mozilla.org/en-US/docs/Web/API/Document/height] which is following the HTML5 specification standard: {quote} Note: Starting in Gecko 6.0, document.height is no longer supported. Instead use document.body.clientHeight. See element.clientHeight. {quote} And for Android, [https://developer.android.com/guide/webapps/migrating.html] the WebView was changed on Android 4.4 onwards to Chromium. This is possibly why this behavior changed from Android 4.4.4 onwards. {quote} This change upgrades WebView performance and standards support for HTML5, CSS3, and JavaScript to match the latest web browsers {quote} Therefore, I believe the best answer would be [~kaiiserni]'s answer (thanks for your comment!), which is to use:
You shouldn't be using 'document.height'. I believe this should be the answer and the ticket can be resolved as Invalid. [~mrahman] Would this be okay for you?var _height = _html_view.evalJS("Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);");If there's nothing else, I'll close this ticket tomorrow.