getClientRects javascript method supported on iPhone?
Trying to find the top-most visible element in a UIWebView
. I am using a JS method to do this, which works great in Safari, but never executes past the getClientRects
method when executed from a UIWebView
. The elements I'm interested are all of class="h"
.
Here's the javascript which is called from [webView stringByEvaluatingJavaScriptFromString:@"findTopElement()"];
Javascript:
function findTopElement() {
var pars = document.getElementsByClassName("h");
alert("findingTopElement: num pars:" + pars.length);
for (var i = 0; i < pars.length; i++) {
var para = pars[i];
alert("checking par " + para.id);
var rects = para.getClientRects();
alert("checking rects " + rects.length);
for (var j = 0; j < rects.length; j++) {
var r = rects[j];
if (r.top > 0 &&a开发者_运维知识库mp; r.bottom > 0) {
alert("success: " + para.id);
return para.id;
}
}
}
return -1;
}
Is it possible element getClientRects function is not supported in a UIWebView
?
It may not be supported by UIWebView yet.
Looks like it was just recently added to Safari so UIWebView may not have support for it.
Maybe there is another way you can catch this butterfly?
http://sideshowbarker.net/?p=45
精彩评论