views:

86

answers:

1

Hello all,

I have UIWebView loaded with an HTML file. I want to know the position (means x and y cordinates) of an HTML element on the screen when the webview is loaded.

Thanks in advance

A: 

You may need to a combination of JavaScript and Objective-C to achieve this. You need a JavaScript functino to pass back the screen position of certain element, and then translate that position to the screen on the iPhone.

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

One way is to write a JavaScript that takes an element ID and returns its position and the screen resolution. Then translate that to the webview resolution on iPhone screen. It gets trickier if the user is allowed to zoom and pan the webview though.

William
Sorry I dont know how to write javaScript. Can we write a java script in which give my screen resolution as argument and then it can return me the element position?
Ideveloper
With JQuery, you can get the size of the HTML document with $(document).height() and $(document).width(), as well as the position of a particular element: $('#element-id').position().
William