任何人都可以幫助我如何在JavaScript處理方向變化事件,通過一個UIWebView在iphone訪問時?如何處理內部的UIWebView JavaScript的onorientationchange事件
我試圖捕捉onorientationchange
事件的JavaScript。我試過下面的代碼。
<style type="text/css" media="only screen and (max-device-width: 480px)">
.portrait
{
width: 300px;
padding: 0 15px 0 5px;
}
.landscape
{
width: 460px;
padding: 0 15px 0 5px;
}
</style>
<script type="text/javascript">
window.onload = orientationchange;
window.onorientationchange = orientationchange;
function orientationchange() {
if (window.orientation == 90
|| window.orientation == -90) {
document.getElementById('contents').className = 'landscape';
}
else {
document.getElementById('contents').className = 'portrait';
}
}
</script>
// and I have a div inside html
<div id="contents">
my contents and description... e.t.c, and e.t.c...
</div>
它工作在Safari罰款,但是當我前往,並使用UIWebView的方向改變事件的頁面沒有被捕獲和我期望的功能不能被來達到的。
我不需要當地的資源,我只是想捕捉的方向變化事件在我的HTML的JavaScript – 2011-03-07 14:53:53
我加了一個引號從我試着不成功顯示您的帖子。這實際上是你所說的問題。 – 2011-03-07 14:59:27
耶謝謝;我的問題解決了。但在應用程序中使用定向啓用的html頁面很奇怪。 – 2011-03-07 18:39:46