System.Windows.WebBrowser捕获页面的图像,该页面以怪癖模式呈现 [英] System.Windows.WebBrowser captures image of page as its rendered in quirks mode
问题描述
我正在使用以下链接将网页捕获为图像 ^ ]
在几个页面上,我遇到的问题是创建的图像与实际页面不相似,但与在怪癖模式下显示的页面相同(页面被弄乱了).
有没有办法以编程方式更改控件的行为(不进行任何注册表更改)
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屋!