How to put the WebBrowser control into IE9 into standards? - com

i am using automation (i.e. COM automation) to display some HTML in Internet Explorer (9):
ie = CoInternetExplorer.Create;
ie.Navigate2("about:blank");
webDocument = ie.Document;
webDocument.Write(szSourceHTML);
webDocument.Close();
ie.Visible = True;
Internet Explorer appears, showing my html, which starts off as:
<!DOCTYPE html>
<HTML>
<HEAD>
...
Note: the html5 standards-mode opt-in doctype html
Except that the document is not in ie9 standards mode; it's in ie8 standards mode:
If i save the html to my computer first:
and then view that html document, IE is put into standards mode:
My question is how update my SpawnIEWithSource(String html) function to throw the browser into standards mode?
void SpawnIEWithSource(String html)
{
Variant ie = CoInternetExplorer.Create();
ie.Navigate2("about:blank");
webDocument = ie.Document;
webDocument.Write(html);
webDocument.Close();
ie.Visible = true;
}
Edit: A more verbose, less understandable or readable code sample, that doesn't help further the question might be:
IWebBrowser2 ie;
CoCreateInstance(CLASS_InternetExplorer, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_WebBrowser2, ie);
ie.AddRef();
ie.Navigate2("about:blank");
IHtmlDocument doc;
dispDoc = ie.Document;
dispDoc.AddRef();
dispDoc.QueryInterface(IHTMLDocument2, doc);
dispDoc.Release()
doc.Write(html);
doc.Close();
doc.Release();
ie.Visible = true;
ie.Release();
Update
Commenter asked on the ieblog entry Testing sites with Browser Mode vs. Doc Mode:
Can we get a description of how the document mode is determined when the HTML content is within an embedded webcontrol? Seems to be that the document mode is choosen differently - maybe for compatibility reasons?
MarkSil [MSFT] responded:
#Thomas: Thanks for raising that question. The WebBrowser Control determines the doc mode the same way that IE does because it contains the same web platform (e.g. there is one shared mshtml.dll across IE and WebBrowser Control hosts). The WebBrowser Control does default to the Compatibility View browser mode, which means that the default doc mode is IE7. Here is a blog post with more detail on this: blogs.msdn.com/.../more-ie8-extensibility-improvements.aspx.
To which Thomas responded:
#MarcSil (re: WebBrowser Control)
The problem with using registry entries to select document mode for WebControl is that it applies to the application as a whole. I write plugins for Google SketchUp where you have WebDialog windows to create UIs - it's just a WebBrowser control in a window. But that leads to problems as I want to force a document mode for my instance of the WebBrowser control, not for all of SU's WebBrowser controls as a whole.
So, my question is: how do you control the document mode per instance for a WebBrowser control?

Have you tried setting in your html the
<meta http-equiv="X-UA-Compatible" content="IE=9" />
or
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
which means latest version

The IE9 "version" of the WebBrowser control, like the IE8 version, is actually several browsers in one. Unlike the IE8 version, you do have a little more control over the rendering mode inside the page by changing the doctype. Of course, to change the browser mode you have to set your registry like the earlier answer. Here is the location of FEATURE_BROWSER_EMULATION:
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
SOFTWARE
Microsoft
Internet Explorer
Main
FeatureControl
FEATURE_BROWSER_EMULATION
contoso.exe = (DWORD) 000090000
Here is the complete set of codes:
9999 (0x270F) - Internet Explorer 9.
Webpages are displayed in IE9
Standards mode, regardless of the
!DOCTYPE directive.
9000 (0x2328) - Internet Explorer 9. Webpages containing standards-based !DOCTYPE
directives are displayed in IE9 mode.
8888 (0x22B8) -Webpages are
displayed in IE8 Standards mode,
regardless of the !DOCTYPE directive.
8000 (0x1F40) - Webpages containing
standards-based !DOCTYPE directives
are displayed in IE8 mode.
7000 (0x1B58) - Webpages containing
standards-based !DOCTYPE directives
are displayed in IE7 Standards mode.
The full docs:
http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation

FEATURE_BROWSER_EMULATION does not works with CoInternetSetFeatureEnabled. The documentation of INTERNETFEATURELIST is not updated since IE7.
Since the feature setting is under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl you may be able to override the value in your process via a registry API hook.

Related

What "magic" causes "cnn.com" when typed in IE11 to automatically launch Edge (Chromium)?

I just noticed that when I typed in "cnn.com" into the IE11 address bar (Windows 10), that it automatically launched the website in Edge (Chromium) instead, then rendered this bar at the top of the site in Edge.
(it also looked like if this was the only tab in IE, it auto closed IE)
I like this new behaviour to help migrate users over from IE, but sadly I could not detect how this is done code wise by CNN.
I looked in Fiddler, scanned the HTTP Headers, and the meta tags on the site... e.g.
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
and the IE only comment tags:
<!--[if lte IE 9]><meta http-equiv="refresh" content="1;url=/2.250.0/static/unsupp.html" /><![endif]-->
but I don't see anything specific that seems to be triggering this? I'd certainly like to entertain applying similar behaviour to some sites/apps that I work on.
FWIW, it also triggers (if you try it enough times) this message to remain in IE11:
https://support.microsoft.com/en-us/office/the-website-you-were-trying-to-reach-doesn-t-work-with-internet-explorer-8f5fc675-cd47-414c-9535-12821ddfc554?ui=en-us&rs=en-us&ad=us
Edge 87 installs a browser helper object called IEToEdgeBHO that performs this redirection based on a pre-provisioned site list (https://edge.microsoft.com/neededge/v1)
Inside Edge, see edge://settings/?search=Internet%20Explorer for the setting that enables/disables this feature.

overwrite X-UA-Compatible meta in SharePoint 2010

I am working on SharePoint 2010 and I want to use
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
for a specific page.
The master page is setting it to "IE=8" which doesn't allow me to use box-shadow in CSS e.g.
I don't have access to the masterpage to change it.
Also I have read that changing that meta in master page is not recommended as it might cause issues with other things like calendars or whatever.
So my Q is: is there any way of overwriting the X-UA-Compatible meta tag in a simple page (.aspx)?
Among the ways to change the compatibility mode for page two of them seems promising:
Via X-UA-compatible HTTP header: The web server has requested a legacy document mode via an HTTP header.
Via X-UA-compatible meta tag: The webpage developer used a meta tag to specify a legacy document mode.
SharePoint 2010's default master page hardcodes X-UA-Compatible meta tag, and meta tag takes precedence over HTTP header, so this can't be done on HTTP level. This leaves us with the second option.
It seems that the first X-UA-compatible meta tag encountered on the page is used by IE (although it's ambiguous in different articles and missing in MSDN documentation). If you write SharePoint UserControl or WebPart you might add this code e.g. in Page_Load() method to add this header as the first one:
HtmlMeta metaEdgeIE = new HtmlMeta();
metaEdgeIE.HttpEquiv = "X-UA-Compatible";
metaEdgeIE.Content = "IE=EDGE";
Page.Header.Controls.AddAt(0, metaEdgeIE);
where HtmlMeta comes from System.Web.UI.WebControls namespace.
By iterating through Page.Header.Controls you could probably also find and remove the meta tag added by default by SharePoint, although the code above seems enough to trigger Edge mode in IE11.
If you can edit the master page and only want to change the compatibility for particular pages you can take a similar approach to buli (thanks) but overwrite the existing Content of the meta tag.
For your meta tag in the master page, give it an id and runat server
<meta id="metaIE" runat="server" http-equiv="X-UA-Compatible" content="IE=edge">
In your page load, find the control from master, cast to HtmlMeta and change the Content
Dim metaIE = DirectCast(Master.FindControl("metaIE"), HtmlMeta)
metaIE.Content = "IE=10"

Fancybox and SharePoint 2010 - position of the iframe

Has anyone experienced problems with using fancybox one a SharePoint page?
I have followed all the instructions and the link opens the iframe with the content but the iframe is opening in one of the divs at the top of the page rather than in the middle of the page.
I have a feeling it is to do with the class of the div as it is called 'Wrapper'.
Does fancybox use 'wrapper' as an explicit value for where the iframe will open? Is this something that I can change as i can't change the div class (that is all set from central admin).
#JFK - thanks for the pointers - turned out to be an older JS file version. I changed that to the latest version and it works perfectly.

How to trigger 'quirks mode' is IE 10

Background:
The issue I'm facing is actually related to printing a webpage. The page is (almost) valid HTML 5 (with a few <table>s with cellpadding, and some <img>s without alts etc). I have a print stylesheet that prints nicely in all the browsers we are supposed to support (latest Chrome, FF and IE) except IE 10.
We have specific requirements about the print layout (which is significantly different from the web layout). We cannot use a separate page designed for printing as most of the page's content is generated using lots of inputs from the user within JavaScript. One of our print layout requirements is that the printout be on exactly 3 pages with specific parts on specific pages. Its working in all browsers we are supporting except IE 10.
In IE 10, the print out is 6 pages (3 in all others) working with the standard "Shrink To Fit" setting. Now I could go around writing a separate print stylesheet for IE 10 but that just seems like too much work.
While playing around with the IE 10 dev tools, I noticed that if I select "Quirks" "Document Mode" and then print, it fits nicely in 3 pages. So the simplest solution to my printing problem seems to be to somehow trigger quirks mode in IE 10 (but not in IE 11 where it already works).
The actual question:
So the question is, how do I trigger quirks mode in IE 10 without triggering it in IE > 10. This MSDN page says
If a page doesn't contain a <!DOCTYPE> directive, Internet Explorer displays the page in quirks mode by default.
So I tried doing the following with my doctype declaration:
<!--[if gt IE 10]>
<!DOCTYPE html>
<![endif]-->
That didn't trigger quriks mode in IE 10 for me. What will?
You can use a meta tag to controll how the page should render:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10">
This will cause the page to be rendered in IE10 mode if a DOCTYPE is present otherwise it will fallback to quirksmode. You can check this link to msdn to see the different X-UA-Compatible modes that can be used.
So if you want IE10 to always render the page in quirksmode you ought to be able to force it using:
<meta http-equiv="X-UA-Compatible" content="IE=5">

how to open specific page on Google's docs viewer

I'm using google's docs viewer to show a pdf document in a html page and I would like to open the document starting on page 20 instead of 1 for example.
There's hardly any documentation about Google's docs viewer service. They say in its webpage https://docs.google.com/viewer that the service only accepts two parameters (url and embedded) but I've seen other parameters searching the web, like "a", "pagenumber", "v" and "attid", none of them did anything to me. I've tried to add #:0.page.19 at the end of my url (that's the id of the div containing page number 20 inside the body google creates) but it just ignores it or works in a random way.
Do you guys know how to tell google docs viewer to show the document starting on a specific page?
I found a solution I'll post here just in case somebody is in the same situation.
Every page inside google's docs viewer iframe has an id like :0.page.X, being X the number of the page. Calling the service like this
<iframe id="iframe1" src="http://docs.google.com/gview?url=http://yourpdf&embedded=true#:0.page.20">
won't work (maybe because the pages ids are not yet created when the page is rendered?)
So you just have to add an onload attribute to the iframe:
<iframe id="iframe1" src="http://docs.google.com/gview?url=http://yourpdf&embedded=true" onload="javascript:this.contentWindow.location.hash=':0.page.20';">
and voilĂ , the iframe will automatically scroll down after loading.
Note that page indices are zero-based. If you want to view the 20th page of a document in the viewer, you would need use the parameter :0.page.19
I found these two ones :
1) just an Screenshot(Image) of specific page (without navigation):
https://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true&a=bi&pagenumber=12
2) a link to specific page of PDF in IFRAME (with navigation):
<script>
var docURL='https://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true';
var startPAGE=7;
document.write('<iframe id="iframe1" onload="javascript:go_to_page('+ startPAGE +')" src="https://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true"width="600" height="400" ></iframe>');
function go_to_page(varr) { document.getElementById("iframe1").setAttribute("src", docURL + '#:0.page.'+ (varr-1) );}
</script>
p.s. then you can have on your website go to page 3
For me this solution didn't work with the current version of google viewer. Link to specific page on Google Document Viewer on iPad helped me out. Use &a=bi&pagenumber=xx as additonal URL parameter.
Got it working in the imbed viewer
By changing the url with a timout function, this becous the pdf is not directly shown
$(window).load(function() {
setTimeout(function() { $('.gde-frame').attr('src', 'https://docs.google.com/viewer?url=http://yourdomain.com/yourpdf.pdf&hl=nl&embedded=true#:0.page.15'); }, 1000);
});
Just copy the imbed url and add your hash for the page (#:0.page.15 > will go to page 15)
You might want to change the language to your own &hl=nl
and for the people how have to support ie8
if you use a boilerplate like this:
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
you can change the output of the link directly to the pdf like this,
if( $("html").hasClass("ie8") ) {
$('#linkID').attr('href', 'http://yourdomai.com/yourpdf.pdf');
};
the pdf will be shown in the pdf reader from IE
My PDF is 13 pages, but when I used hash: 0.page.13, it only jumped to page 10. I had to setTimeout and call the same function again:
Only needed to do that once per page load, then it seems to be synched properly. I am sure there is a more elegant solution:
var is_caught_up = false;
function pdf_go(page){
$('pdf_frame').contentWindow.location.hash=':0.page.'+page;
if (!is_caught_up){
setTimeout('pdf_catchup('+page+')', 500);
}
}
function pdf_catchup(page){
$('pdf_frame').contentWindow.location.hash=':0.page.'+page;
is_caught_up = true;
}