getClientRects javascript method supported on iPhone?

Posted by genericdan on Stack Overflow See other posts from Stack Overflow or by genericdan
Published on 2009-10-31T12:31:32Z Indexed on 2010/06/13 17:02 UTC
Read the original article Hit count: 171

Filed under:
|

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 && r.bottom > 0) {
    alert("success: " + para.id);
    return para.id;
   }
  }
 }
 return -1;
}

Is it possible element getClientRects function is not supported in a UIWebView?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about iphone