iOS WebView获取页面元素
document:属性
• document.title //设置文档标题等价于HTML的
• document.bgColor //设置页面背景色
• document.fgColor //设置前景色(文本颜色)
• document.linkColor //未点击过的链接颜色 document.alinkColor//激活链接(焦点在此链接上)的颜色
• document.vlinkColor //已点击过的链接颜色
• document.URL //设置URL属性从而在同一窗口打开另一网页
• document.fileCreatedDate //文件建立日期,只读属性
• document.fileModifiedDate //文件修改日期,只读属性
• document.fileSize //文件大小,只读属性
• document.cookie //设置和读出cookie
• document.charset //设置字符集 简体中文:gb2312 document:方法
• document.write() //动态向页面写入内容
• document_createElement_x_x(Tag) //创建一个html标签对象
• document.getElementByIdx_x_x(ID) //获得指定ID值的对象
• document.getElementsByName(Name) //获得指定Name值的对象
• document.body.a(oTag)
body:子对象
• document.body //指定文档主体的开始和结束等价于
• document.body.bgColor //设置或获取对象后面的背景颜色
• document.body.link //未点击过的链接颜色
• document.body.alink //激活链接(焦点在此链接上)的颜色
• document.body.vlink //已点击过的链接颜色
• document.body.text //文本色
• document.body.innerText //设置…之间的文本
• document.body.innerHTML //设置…之间的HTML代码
• document.body.topMargin //页面上边距
• document.body.leftMargin //页面左边距
• document.body.rightMargin //页面右边距
• document.body.bottomMargin //页面下边距
• document.body.background //背景图片
• document.body.a(oTag) //动态生成一个HTML对象
location:子对象
• document.location.hash // #号后的部分
• document.location.host // 域名+端口号
• document.location.hostname // 域名
• document.location.href // 完整URL
• document.location.pathname // 目录部分
• document.location.port // 端口号
• document.location.protocol // 网络协议(http:)
• document.location.search // ?号后的部分
常用对象事件:
• documeny.location.reload() //刷新网页
• document.location.reload(URL) //打开新的网页
• document.location.assign(URL) //打开新的网页
• document.location.replace(URL) //打开新的网页
• selection-选区子对象
• document.selection
网页长截图
- (UIImage *)snapshotViewFromRect:(CGRect)rect withCapInsets:(UIEdgeInsets)capInsets {
CGFloat scale = [UIScreen mainScreen].scale;
CGSize boundsSize = self.webView.bounds.size;
CGFloat boundsWidth = boundsSize.width;
CGFloat boundsHeight = boundsSize.height;
CGSize contentSize = self.webView.scrollView.contentSize;
CGFloat contentHeight = contentSize.height;
// CGFloat contentWidth = contentSize.width;
CGPoint offset = self.webView.scrollView.contentOffset;
[self.webView.scrollView setContentOffset:CGPointMake(0, 0)];
NSMutableArray *images = [NSMutableArray array];
while (contentHeight > 0) {
UIGraphicsBeginImageContextWithOptions(boundsSize, NO, [UIScreen mainScreen].scale);
[self.webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[images addObject:image];
CGFloat offsetY = self.webView.scrollView.contentOffset.y;
[self.webView.scrollView setContentOffset:CGPointMake(0, offsetY + boundsHeight)];
contentHeight -= boundsHeight;
}
[self.webView.scrollView setContentOffset:offset];
CGSize imageSize = CGSizeMake(contentSize.width * scale,
contentSize.height * scale);
UIGraphicsBeginImageContext(imageSize);
[images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) {
[image drawInRect:CGRectMake(0,
scale * boundsHeight * idx,
scale * boundsWidth,
scale * boundsHeight)];
}];
UIImage *fullImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView * snapshotView = [[UIImageView alloc]initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
snapshotView.image = [fullImage resizableImageWithCapInsets:capInsets];
return snapshotView.image;
}
监听webview高度变化
[webViewObj.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if ([keyPath isEqualToString:@"contentSize"]) {
CGSize fittingSize = [webViewObj sizeThatFits:CGSizeZero];
[ESHKSingle singleShare].scrollerRect = CGRectMake(0, 0, ScreenWidth,fittingSize.height);
NSLog(@"screenshotView hight %f ===",fittingSize.height);
}
}
相关参考:
http://blog.csdn.net/wenmingzheng/article/details/50493658?utm_source=itdadao&utm_medium=referral
网友评论