Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    117
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How do I explain... XMLHttpRequest?

    Hi guys, this isn't a normal question but I am still hoping you can all help me out.


    This is a code I have used for awhile, but I honestly don't know how it works, I just know it does.

    I am loading 2 different CSS files with:

    Code:
     
    <!--
     if (window.XMLHttpRequest)
    {
     document.write('<link rel="stylesheet" type="text/css" href="mainStyle.css" />')
    }
    
    
     else
    {
     document.write('<link rel="stylesheet" type="text/css" href="ieStyle.css" />')
    }
    //-->
    How would I explain how the if statement if (window.XMLHttpRequest) works?

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    In what context? It's object detection. You're looking to see if the current window object supports an XMLHttpRequest object.

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    UM, someone used that to detect non IE browsers, but IE7 now supports that so it will use that style sheet probably breaking the changes.

    I think you better find a new way to do CSS includes. A lot of people around here will say why bother having two when you can try to work in one? Normally a missing DOC-TYPE is the reason why IE is different.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    117
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It isn't a missing Doctype. My entire site is XHTML 1.0 Strict and It all validates, aswell as my code. But for some reason in IE 6 and below, added my padding to the width of a div instead of inserting the padding into the div.

    So I basically made two CSS files that were generally the same, accept for that small detail, and one was for IE 6- and the other was for all other browsers including IE7
    In what context? It's object detection. You're looking to see if the current window object supports an XMLHttpRequest object.
    I know what the script does but what does XMLHttpRequest actually do? I tried googling it but I can't really understand most of the explainations. Something about sending XML through HTML?

    It would probably help if I knew XML.

  • #5
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The XMLHttpRequest object creates a call to the server. This call returns a page that you can use to update the page that made the call back to the server.

    http://en.wikipedia.org/wiki/XMLHttpRequest
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You can do it using IE conditionals in your HTML and not require any Javascript at all. The following will override the main stylesheet settings with IE specific ones in IE6 and earlier regardless of whether Javascript is enabled or not.

    Code:
    <link rel="stylesheet" type="text/css" href="mainStyle.css" />
    <!--[if IE lte 6]>
    <link rel="stylesheet" type="text/css" href="ieStyle.css" />
    <[endif]-->
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •