RSS

HTTP Streaming and Internet Explorer

25 Sep

Michael Carter wrote about the trials and tribulations of getting HTTP streaming with IE. He knew that the htmlfile ActiveX object was the key, but kept getting errors.

Then he stumbled on the solution:

We happen to be in luck. Changing JavaScript variables, including Array functions, seems okay as far as the gods of htmlfile streaming are concerned. So our solution is to simply append event payloads to an array from within the iframe, have the parent window use use a timer loop (’setInterval’) to periodically check the array for new messages, and then pass them to the callback. It’s not as elegant as I’d like…but it beats all the other techniques I’ve tried.

Why not just call a function attached the parent window, you wonder? It turns out htmlfile’s iframe doesn’t care where the function object lives; instead, it cares which thread is used to execute the code. The htmlfile thread is a capricious beast, and will rebel when employed to do too much DOM work. The effect of setInterval is to move the actual DOM manipulations to a thread that is perfectly safe for that sort of scripting. This fix works for IE 5.01+.

Michael just put up another post that details the solution after learning about the nuances of IE. He ended up using the following code:

JAVASCRIPT:

  1. function connect_htmlfile(url, callback) {
  2. // no more ‘var transferDoc…’
  3. transferDoc = new ActiveXObject(“htmlfile”);
  4. transferDoc.open();
  5. transferDoc.write(
  6. “<html><script>” +
  7. “document.domain='” + document.domain + “‘;” +
  8. “</script></html>”);
  9. transferDoc.close();
  10. var ifrDiv = transferDoc.createElement(“div”);
  11. transferDoc.body.appendChild(ifrDiv);
  12. ifrDiv.innerHTML = “<iframe src='” + url + “‘></iframe>”;
  13. transferDoc.callback = callback;
  14. }

And in the iframe:

HTML:

  1. <script>parent.callback([“arbitrary”, “data”, [“goes”, “here”]);</script>
Advertisements
 
Leave a comment

Posted by on September 25, 2008 in COMET

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: