【发布时间】:2011-03-07 14:41:08
【问题描述】:
任何人都可以帮助我在通过 iPhone 中的uiwebview 访问时如何处理 Javascript 中的方向更改事件?
我正在尝试捕获 Javascript 的 onorientationchange 事件。我尝试了以下代码:
<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 访问页面时,没有捕获方向更改事件,并且无法实现我想要的功能。
【问题讨论】:
标签: javascript ios uiwebview dom-events orientation