Created
June 6, 2013 12:38
-
-
Save darcwader/5721194 to your computer and use it in GitHub Desktop.
This calculates the height of webview based on the html page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableString *js = [NSMutableString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"individualnotification" ofType:@"js"] encoding:NSUTF8StringEncoding error:nil]; | |
[js appendString:@"getHeightForElementById(\"idNotificationContent\")"]; | |
float height = [[contentWebView stringByEvaluatingJavaScriptFromString:js] floatValue]; | |
function getHeightForElementById(elementID) { | |
var height = 0; | |
var subElements = Array(); | |
var element = document.getElementById(elementID); | |
subElements = element.getElementsByTagName("div"); | |
for (var i = 0; i < subElements.length; i++) { | |
var subElement = subElements[i]; | |
var elementHeight = subElement.offsetHeight; | |
height += elementHeight; | |
} | |
subElements = element.getElementsByTagName("table"); | |
for (var i = 0; i < subElements.length; i++) { | |
var subElement = subElements[i]; | |
var elementHeight = subElement.offsetHeight; | |
height += elementHeight; | |
} | |
return height; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment