UIWebView window.innerWidth = 0

时间:2013-09-24 14:41:50

标签: javascript ios uiwebview frameset

我有两个简单的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>

和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注入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];

1 个答案:

答案 0 :(得分:1)

尝试将脚本放在2.html中的body标记上方,并在获取body onLoad时触发窗口大小功能。

相关问题