Home > Uncategorized > Microsoft.XMLHTTP to the rescue

Microsoft.XMLHTTP to the rescue

Following up on my previous post regarding forwarding a user to a different page whilst another page is loading. I came up with a solution.
 
If you are loading a page from http://localhost, you cannot simultaneously load a page from localhost in the same session. This, I guess is a browser quirk, but nonetheless, it effects both IE and Firefox. However, you can load a page from http://127.0.0.1 – even though they’re the same server.
 
In the particular applcation I was working on, it was not acceptable to change domains, since the referer would change. Therefore, after about 4 hours of research, I read up on XMLHTTP – a technology used for out-of-band calls – as I used earlier in a .NET chatroom application.
 
So to get right to the code – here it is:
 
function openWindow(url)
{
 var xmlhttp=false;
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
 // JScript gives us Conditional compilation, we can cope with old IE  versions.
 // and security blocked creation of the objects.
 try {
 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
 try {
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (E) {
 xmlhttp = false;
 }
 }
 @end @*/
 if (!xmlhttp && typeof XMLHttpRequest!=’undefined’)
 {
  xmlhttp = new XMLHttpRequest();                                           
 } 
 
 try
 {                  
  xmlhttp.open("GET", "http://<alternative URL>/" + url,true);
  win=window.open();
  xmlhttp.onreadystatechange=function()
  {                  
   if (xmlhttp.readyState==4)
   {                    
    win.document.write(xmlhttp.responseText);                 
   }
  }
  xmlhttp.send(null)  
 }
 catch(e2)
 {
  // The browser doesn’t support XMLHTTP.
  window.open(url);
 }
}   
 
Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

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: