Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
Posted
Updated 3-Aug-12 4:48am
v2

1 solution

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:

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


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:

C#
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);
}


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/
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900