System.Windows.WebBrowser捕获页面的图像,该页面以怪癖模式呈现 [英] System.Windows.WebBrowser captures image of page as its rendered in quirks mode

查看:40
本文介绍了System.Windows.WebBrowser捕获页面的图像,该页面以怪癖模式呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下链接将网页捕获为图像

I am using following link to capture web page as image http://stackoverflow.com/questions/2715385/convert-webpage-to-image-from-asp-net[^]

On few pages I am getting issue where the image created is not similar to actual page but its same as to page displayed in quirks mode(where the page is messed up).
Is there any way to programmatically change the behavior of control(without making any registry changes)

推荐答案

一种可能的解决方案是强制执行某种呈现方式.本质上,将下面的meta标签发送到文档中(以ie9模式呈现).如果文档中已经存在该文件,则可能需要替换它:

One possible solution would be to enforce a certain mode of rendering. Essentially, emit the below meta tag into the document (to render in ie9 mode). You will probably have to replace it if one already exists in the document:

<meta http-equiv="X-UA-Compatible" content="IE=9"></meta>



其中内容"是您在可用列表中所需的值之一:
http://msdn.microsoft.com/zh-CN/library/ie/ms533876(v = vs.85).aspx [



Where "content" is one of the values you need in the available list: http://msdn.microsoft.com/en-us/library/ie/ms533876(v=vs.85).aspx[^]

With code similar to below:

var web = <your webbrowser control>;
var doc = web.Document;
var allMetas = doc.GetElementsByTagName("meta");
var needsReplaced = false;
foreach(HtmlElement meta in allMetas)
{
   var target = meta.GetAttribute("http-equiv").ToLower();
   if(target == "x-ua-compatible")
   {
      needsReplaced = true;
      meta.SetAttribute("content", "IE=9");
   }
}

//add new meta tag if it didn't exist.
if(!needsReplaced)
{
   var meta = doc.CreateElement("meta");
   meta.SetAttribute("http-equiv", "X-UA-Compatible");
   meta.SetAttribute("content", "IE=9");

   var head = doc.getElementsByTagName("head")[0];
   head.AppendChild(meta);
}



资料来源:

MetaTag:http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control

内容"值:http://msdn.microsoft.com/zh-cn/library/ie/ms533876(v=vs.85).aspx

更改MetaTag:http://schroedman.wordpress.com/2010/11/03/c-read-meta-tags-with-webbrowser-control/



Sources:

MetaTag: http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control

"Content" values: http://msdn.microsoft.com/en-us/library/ie/ms533876(v=vs.85).aspx

Change MetaTag: http://schroedman.wordpress.com/2010/11/03/c-read-meta-tags-with-webbrowser-control/


这篇关于System.Windows.WebBrowser捕获页面的图像,该页面以怪癖模式呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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