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

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

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

問(wèn)題描述

我使用 UIWebView 來(lái)顯示內(nèi)容,以 HTML 字符串的形式——不是網(wǎng)站,高于 iPhone 的屏幕,無(wú)需在 webView 本身中滾動(dòng),離開(kāi)到父 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.

為了實(shí)現(xiàn)這一點(diǎn),我需要一種方法來(lái)獲取總文檔大小(包括可滾動(dòng)區(qū)域)來(lái)設(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

有沒(méi)有真正有效的解決方案?

Is there a solution that actually works?

當(dāng)前(非工作)代碼:

[[[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 及更高版本中無(wú)需使用 Javascript - 您可以直接訪問(wèn)它的 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)容的總高度的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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è)面之間的照片應(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 中的可滾動(dòng)區(qū)域)
Setting up UIScrollView to swipe between 3 view controllers(設(shè)置 UIScrollView 在 3 個(gè)視圖控制器之間滑動(dòng))
UIScrollView with quot;Circularquot; scrolling(帶有“圓形的 UIScrollView滾動(dòng))
主站蜘蛛池模板: 午夜影院视频在线观看 | 国产日韩欧美一区 | 91.色| 亚洲国产电影 | 色婷婷国产精品综合在线观看 | 91精品在线看 | 亚洲自拍一区在线观看 | 亚洲一区二区在线视频 | 九九热久久免费视频 | 成人欧美一区二区三区黑人孕妇 | 亚洲国产成人在线 | 欧美视频免费 | 一级在线观看 | www.日本在线 | 精品视频在线免费观看 | 五月婷婷导航 | 日韩免费视频一区二区 | 亚洲视频在线一区 | 国产做a爱片久久毛片 | 日本久久一区 | 日日碰狠狠躁久久躁婷婷 | 一级毛片免费视频观看 | 欧美日韩黄色一级片 | 久久专区| 色www精品视频在线观看 | 国产乱码精品一区二区三区中文 | 亚洲 欧美 日韩在线 | 免费观看日韩av | 三a毛片 | 国产成人99久久亚洲综合精品 | 免费国产一区 | 国产午夜精品福利 | 日本午夜在线视频 | 91最新在线视频 | 日本精品国产 | 国产精品视频久久久 | 免费精品视频在线观看 | 欧美激情一区二区三区 | 欧美性受xxx | 黑人精品欧美一区二区蜜桃 | 在线观看亚洲专区 |