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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Montreal, QC
    Posts
    340
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Changing properties added with the Prototype keyword

    Hi,

    I have some script like this:
    Code:
    // simplified to remove all the try/catches & stuff
    function newXHR() {
     request = new XMLHttpRequest();
     XMLHttpRequest.prototype.requested = null;
     return request;
    }
    then later:
    Code:
    function doRequest(url, callback) {
     var req = newXHR();
     req.requested = url;
    
    // et cetera....
    }
    This works fine in Firefox, however the line 'req.requested = url'; causes an error in IE7, (I haven't tested IE6 yet). The error is 'Object doesn't support this property or method'

    So, this leads me to believe that either a) XMLHttpRequest.requested is not writable, or, b) XMLHttpRequest.requested was never created in the first place. I think it's the first option because I'm not getting an error in the newXHR() function.

    I've been searching for some documentation on this but I can't seem to find anywhere if properties created with the prototype keyword are writeable in IE. Does anyone know what the problem is?

    Thanks,

    John
    Search for Laughter or Just Search?
    GiggleSearch.org
    Blog: www.johnbeales.com
    All About Ballet: www.the-ballet.com

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In IE6 the XMLHttpRequest is an ActiveX object, not a native object so you can't set any custom properties on it.

    IE7 on the other hand should support it.

    http://msdn2.microsoft.com/en-us/library/ms537505.aspx

    Plus I did this quick test on a straight custom property and it worked

    Code:
    <html>
      <head>
        <title>Junque</title>
        <script type="text/javascript">
          function doIt(s) {
            var adiv = document.getElementById("adiv");
            var xhr = new XMLHttpRequest();
            xhr.custom_prop = "hiya";
            adiv.innerHTML = xhr.custom_prop;
          }
        </script>
      </head>
      <body>
        <div>
          <button onclick="doIt();">Do it</button>
          <br />
          <div id="adiv"> </div>
        </div>
      </body>
    </html>
    But the question was about prototype and from what I read the "native" xhr for IE7 is still not truly native so you can't add to its prototype. Nor can you add to the XMLHttpRequest object itself, so only its instantiated objects.

    That's my brain dump on it anyway. ;)

    david_kw


  •  

    Posting Permissions

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