晚上好,
我一直在使用内部具有 webview 的视图时遇到一些问题。webview 正在插入一个带有外部源的 iframe(另一个域上的 html)。我正在使用 iframe,因为我需要使用外部 HTML,并且我需要与我的应用程序与点击/触摸事件进行通信。
主要问题是 webview 正在插入不需要的水平滚动条(因为 iframe 内容太大)
代码如下所示:
网页浏览:
var webview = Titanium.UI.createWebView({
    url: "/html/local.html",
    width:Ti.UI.SIZE,
    height:Ti.UI.SIZE,
    contentWidth:Ti.UI.SIZE,
    contentHeight:Ti.UI.SIZE,
    disableBounce:true,
    enableZoomControls: false
});
self.add(webview);
框架:
<html>
    <head>
        <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
        <meta http-equiv="cleartype" content="on">
        <script>
            function init () {
                window.theIframe.TiAPI = Ti.API;
                window.theIframe.TiApp = Ti.App;
            }
        </script>               
        <style>
            body {width:100%;margin:0;padding:0;background-color:#ccffff;}
        </style>
    </head>
    <body>
        <iframe name="theIframe" src="http://external.com/something.html" width="100%" height="100%" frameborder="0" onload="init()">
        </iframe>
    </body>
</html>
注意事项:
- 这只发生在肖像上。它在 iPad 或 iPhone 上运行良好,具有横向视图。
- 如果在外部 html 下,我将 body 的最大宽度设置为 320px,它可以完美地工作。我不会这样做,因为我需要它在横向和 iPad 下工作。
- 如果我使用外部 html 作为 webview 的 URL,它也可以工作。所以这不是外部内容的问题,而是本地 html 或 webview 和 iframe 的问题。
任何想法?