imagiro
imagiro

Reputation: 472

IE and quirks mode in a pluggable protocol handler

I have the following problem:

A pluggable protocol handler deliveres HTML files.

These files don't have a proper doctype - the doctype is completely missing. I can't change this, the files are from a third party.

So I want to use the "X-UA-Compatible: IE=edge" header to set the doctype. When I do this from a real webserver it works as expected. When I do it from the protocol handler via IHttpNegotiate::OnResponse it does not work.

I tried already adding more headers like "Content-Type" and of course "HTTP/1.1 200 OK" up to the point where I report all headers I receive from a real webbrowser - IE still sets the documentMode to 5.

Does anybody have some ideas about this?

Here is what I'm trying:

pOIProtSink->ReportProgress(BINDSTATUS_FINDINGRESOURCE, L"Found");
pOIProtSink->ReportProgress(BINDSTATUS_CONNECTING, L"Connecting");
pOIProtSink->ReportProgress(BINDSTATUS_SENDINGREQUEST, L"Sending");

CComQIPtr<IServiceProvider> provider(pOIProtSink);
if (provider) {
  CComPtr<IHttpNegotiate> negotiate;
  provider->QueryService(IID_IHttpNegotiate, IID_IHttpNegotiate,
      (void**)&negotiate.p);
  if (negotiate) {
    CStringW hdrs;
    hdrs.Format(
      L"HTTP/1.1 200 OK\r\nContent-Type: %s\r\nX-UA-Compatible: IE=edge\r\n\r\n",
      sMime);
    negotiate->OnResponse(200, hdrs, L"", NULL);
  }
}

pOIProtSink->ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, sMime);
pOIProtSink->ReportData(BSCF_FIRSTDATANOTIFICATION, 0, sz);
pOIProtSink->ReportData(BSCF_LASTDATANOTIFICATION
    | BSCF_DATAFULLYAVAILABLE, sz, sz);

pOIProtSink->ReportResult(S_OK, 0, NULL);

And the whole code can be found on github.

Cheers
imagiro

Upvotes: 2

Views: 233

Answers (1)

Spudley
Spudley

Reputation: 168853

As far as I know, when you miss out the doctype it triggers Quirks mode, and that trumps any other attempt to set the mode using X-UA-Compatible.

So the short answer is that your proposed solution is not going to work.

Sorry.

The only other solution I can think of is to wrap the whole thing into an iframe. IE can only use a single rendering mode for a page, including any embedded frames. This means that if the parent page is in standards mode, then any iframes will also be in standards mode, even if they would normally be in quirks mode or compatibility mode.

I've seen a number of questions here recently complaining about this, where people are trying to plug new code into an old quirks mode site or vice-versa, and struggling with the inability to specify the mode for the iframe. But in your case, this could work to your advantage, in that if you can inject the content into an iframe, then you will effectively be able to rig the page to be into whatever mode you like, based on the mode you specify for the parent page. Make the iframe fill the entire page and you've got a solution.

That's the only way I can think of to force your page into standards mode.

Of course, it would be a lot easier if you could just inject the doctype, or even better if the original third party provider could fix their code to include a doctype.

What puzzles me though is that if it doesn't include a doctype and the third party provided it like that, they must have tested it that way, so presumably they're expecting it to run in quirks mode? Given that, what's the motivation for forcing it into standards mode?

Upvotes: 2

Related Questions