iFrame在iPhone上

时间:2011-03-26 22:05:16

标签: javascript jquery asp.net html

我正在尝试在我的网站上创建一个工具栏,以便在iphone上使用。但是,iframe给了我相当大的麻烦,因为它拒绝允许页面滚动。这是我的代码:

<iframe id="myIFrame" src="http://www.bloomberg.com" 
    runat="server" frameborder="0" style="position: fixed; top: 65px; left: 0px; width: 100%; overflow:auto;"></iframe>

<script type="text/javascript">
    window.onresize = setHeight;

    function setHeight() {
        var myScreenHeight = screenHeight();
        var theIFrame = document.getElementById("myIFrame");
        theIFrame.height = myScreenHeight - document.getElementById("toolbar").clientHeight + "px";

        return false;
    }

    function screenHeight() {
        var myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            myHeight = document.documentElement.clientHeight;
        }
        return myHeight;
    }

    jQuery(document).ready(setHeight);
</script> 

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在iphone上的webkit中无法使用原生滚动和固定位置工具栏。

这个javascript插件通过复制滚动并允许固定位置工具栏解决了这个问题:http://cubiq.org/iscroll-4