Ipad:window.height()在Safari中给出​​了不好的价值但在Chrome中却没有 [英] Ipad: window.height() give bad value in Safari but not in Chrome

查看:387
本文介绍了Ipad:window.height()在Safari中给出​​了不好的价值但在Chrome中却没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在Ipad上获得窗口的高度以显示全高度的东西。

I have to get the window's height on Ipad to display something in the full height.

我做了这个示例页面: http://daviddarx.com/stuffs/work/biceps/ipad/

I have done this example page: http://daviddarx.com/stuffs/work/biceps/ipad/

这是我的js代码,非常简单,只写窗口正文中的.height():

Here is my js code, very simple, that only write the window.height() in the body:

generalResizeListener=function(){
    screenW=$(window).width();
    screenH=$(window).height();
    $("body").html(screenH)
    console.log(screenH);
}
$(window).resize(generalResizeListener);

我的ipad2与IOS7有两个问题:
-In safari,但不是在Chrome中,显示的值不适合实际的页面高度(我在屏幕截图上查看)

There is two problem, on my ipad2 with IOS7: -In safari, but not in Chrome, the displayed value don't fit to the actual page height (I checked on screenshots)

- 在Safari中总是,即使没有任何内容页面,页面的高度比视口大,我可以向下滚动10-20px之类的东西。这是最大的问题。

-In Safari always, even if there isn't anything in the page, the page's height is bigger than the viewport and I can scroll down for something like 10-20px. That is the biggest probleme.

你知道为什么会这样吗?我的演示页面中没有任何css文件,所以我真的不明白。

Do you know why is this happening? I haven't any css files in my demo page, so I really don't understand.

提前感谢您的帮助!
David

Thank you in advance for your help! David

@Gal V:

我已经实现了这个hacky解决方案。无论如何,谢谢你的回答!我在谷歌看起来更多,它似乎是safari IOS7的特定错误:

I already implemented this "hacky solution". Thank you for your answer, anyway! I looked a bit more in google and it seems to be a specific bug of safari IOS7:

- https://discussions.apple.com/message/23150650#23150650

- 在固定网页上滚动问题iOS7中的页眉和页脚

- iOS 7 iPad Safari Landscape innerHeight / outerHeight布局问题

推荐答案

iOS上的Safari浏览器有一个底栏(不像chrome),它在里面窗口高度计算,而它实际上不是窗口/页面的一部分。

Safari browser on iOS has a bottom bar (unlike chrome) that is being calculated inside the window height while it isn't really part of the window/page.

您需要检测客户端使用的案例(使用用户代理) iOS设备上的Safari浏览器,然后你需要将身体的高度(用javascript)设置为 $(窗口).height() - bar_height ,它应该解决你的问题。

you need to detect cases (with user-agent) where the client uses Safari browser on iOS device, and then you need to set the height of the body (with javascript) to $(window).height() - bar_height, and it should solve your problem.

希望有所帮助。

这篇关于Ipad:window.height()在Safari中给出​​了不好的价值但在Chrome中却没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆