我有两个简单的 html 文件,它们显示在我的 UIWebView 应用程序中,其代码: 索引.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>
和2.html:
<html>
<body>
<script>
var iWinWidth = window.innerWidth;
var iWinHeight = window.innerHeight;
alert(window.name + "\n iWinWidth="+iWinWidth+" iWinHeight="+iWinHeight); </script>
</body>
</html>
问题是在2.html中window.innerWidth和window.innerHeight经常为0。我能做什么来解决这个问题?这段代码是用于测试和解决大程序中的问题的小样本,2.html之类的文件是第三方的,我可以更改index.html或将javascript注入(inject)2.html,但不能更改它自己的脚本,因为我不知道它的
在 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 时触发窗口大小函数。
关于javascript - UIWebView window.innerWidth=0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18984698/