I have two simple html files which shows in my app in UIWebView, its code: index.html
<script>
var iWinWidth = window.innerWidth;
var iWinHeight = window.innerHeight;
alert(window.name + "\n iWinWidth="+iWinWidth+" iWinHeight="+iWinHeight);
</script>
<FRAMESET rows="704,..." cols="1024,...">
<FRAME SRC="2.html" name="contentFrame" noresize>
</FRAMESET>
and 2.html:
<html>
<body>
<script>
var iWinWidth = window.innerWidth;
var iWinHeight = window.innerHeight;
alert(window.name + "\n iWinWidth="+iWinWidth+" iWinHeight="+iWinHeight); </script>
</body>
</html>
the problem is that in 2.html window.innerWidth and window.innerHeight are 0 very often. What can I do to solve this? This code is small sample for testing and solving problem in big program, 2.html like files is third party, I can change index.html or inject javascript into 2.html, but not change its own scripts cause I don't know its
Loading file in obj-c:
documentPath=[[[NSBundle mainBundle] pathForResource:@"testFormats" ofType:@""] stringByAppendingPathComponent:documentPath];
NSURL *url = [NSURL fileURLWithPath:documentPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
Try putting your script above the body tag in 2.html and triggering the window size function when you get body onLoad.