[英]UIWebView window.innerWidth=0
I have two simple html files which shows in my app in UIWebView, its code: index.html 我有两个简单的html文件,它们在UIWebView的应用程序中显示,其代码为: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: 和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. 问题是,在2.html window.innerWidth和window.innerHeight通常为0。 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
此代码是用于测试和解决大型程序问题的小样本,像2.html一样的文件是第三方,我可以更改index.html或将javascript注入2.html,但不能更改自己的脚本,因为我不知道它的
Loading file in obj-c: 在obj-c中加载文件:
documentPath=[[[NSBundle mainBundle] pathForResource:@"testFormats" ofType:@""] stringByAppendingPathComponent:documentPath];
NSURL *url = [NSURL fileURLWithPath:documentPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
尝试将脚本放在2.html中的body标签上方,并在获取body onLoad时触发窗口大小函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.