久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Javascript 獲取 webView 內(nèi)容的總高度

Get total height of webView#39;s content using Javascript(使用 Javascript 獲取 webView 內(nèi)容的總高度)
本文介紹了使用 Javascript 獲取 webView 內(nèi)容的總高度的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我使用 UIWebView 來顯示內(nèi)容,以 HTML 字符串的形式——不是網(wǎng)站,高于 iPhone 的屏幕,無需在 webView 本身中滾動,離開到父 scrollView.

I'm using a UIWebView for displaying content, in the form of an HTML string – not a website, higher than the screen of the iPhone, without needing to scroll in the webView itself, leaving that to the parent scrollView.

為了實現(xiàn)這一點,我需要一種方法來獲取總文檔大小(包括可滾動區(qū)域)來設(shè)置 webView 的高度.我嘗試了許多不同的 Javascript 解決方案:

To achieve this, I need a way to get the total document size, including the scrollable area, to set the webView's height. I have tried a number of different Javascript solutions:

(document.height !== undefined) ? document.height : document.body.offsetHeight // Returns height of UIWebView
document.body.offsetHeight // Returns zero
document.body.clientHeight // Returns zero
document.documentElement.clientHeight // Returns height of UIWebView
window.innerHeight // Returns height of UIWebView -2
document.body.scrollHeight // Returns zero

有沒有真正有效的解決方案?

Is there a solution that actually works?

當前(非工作)代碼:

[[[self.singlePost.contentText subviews] lastObject] setScrollEnabled:NO];
int content_height = [[self.singlePost.contentText stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue];
NSLog(@"Content_height: %d", content_height);
CGRect rect = self.singlePost.contentText.frame;
rect.size.height = content_height;
self.singlePost.contentText.frame = rect;

推薦答案

在 iOS 5.0 及更高版本中無需使用 Javascript - 您可以直接訪問它的 scrollView:

There is no need to use Javascript in iOS 5.0 and up - you have direct, documented access to its scrollView:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGFloat contentHeight = webView.scrollView.contentSize.height;
    // ....
}

獲取webView內(nèi)容的總高度.

To get the total height of the contents of the webView.

這篇關(guān)于使用 Javascript 獲取 webView 內(nèi)容的總高度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
Limiting the scrollable area in UIScrollView(限制 UIScrollView 中的可滾動區(qū)域)
Setting up UIScrollView to swipe between 3 view controllers(設(shè)置 UIScrollView 在 3 個視圖控制器之間滑動)
UIScrollView with quot;Circularquot; scrolling(帶有“圓形的 UIScrollView滾動)
主站蜘蛛池模板: 中文在线免费看视频 | 五十路av| 国产精品一区二区三区免费 | 欧美一区在线视频 | 免费网站黄色 | av网站网址 | 丰满少妇高潮 | 亚洲成人免费在线 | 日本少妇视频 | 日日干天天射 | 亚洲一区在线免费观看 | 欧美一区二区三区的 | 99精品视频免费观看 | 国产黄色片在线观看 | 精品少妇3p| 蜜臀99久久精品久久久久小说 | 天天草天天干 | 欧美日韩视频在线 | 日韩色网 | 国产福利视频 | 欧美成人极品 | 色啪视频| 天天躁日日躁狠狠躁 | 中文在线观看免费高清 | 黄色免费观看视频 | 日韩精品极品 | 日韩欧美在线免费观看 | 黄色片在线播放 | 久久免费观看视频 | 亚欧在线观看 | 国产视频一区二区在线 | 91精品国产综合久久久久久 | 国产精品99久久久久久久久 | www.国产精品 | 黄色在线播放 | 国产一区二区久久 | 亚洲一级片在线观看 | 亚洲国产日本 | 国产青青操 | 啪啪毛片 | 久久99视频 |