Bug Tracker

Opened 10 years ago

Closed 10 years ago

#6500 closed bug (worksforme)

document.domain + IE6 + jQuery 1.4.x = "Permission denied" error

Reported by: cowboy Owned by:
Priority: Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

After setting document.domain, I get a "Permission denied" error when accessing the location.hash properties immediately or in DOM ready in IE6 if jQuery 1.4.x is included in the page.

Test-cases:

Sample code

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
  
  document.domain = document.domain.split('.').slice(-2).join('.');
  
  var results = [];
  
  // Error!
  try {
    results.push( 'Immediate: ' + location.href );
  } catch(e) {
    results.push( 'Immediate: ' + e.message )
  }
  
  // Error when executed in the body, but not in the head!
  $(function(){
    try {
      results.push( 'DOMready: ' + location.href );
    } catch(e) {
      results.push( 'DOMready: ' + e.message )
    }
  });
  
  // No error!
  setTimeout(function(){
    try {
      results.push( 'setTimeout: ' + location.href );
    } catch(e) {
      results.push( 'setTimeout: ' + e.message )
    }
  }, 100);
  
  setTimeout(function(){
    alert( results.join( "\n---\n" ) );
  }, 1000);
  
</script>

Change History (11)

comment:1 Changed 10 years ago by cowboy

It's not just IE6, but IE7 too. IE8 and IE8-compat mode seem to work fine. My observations:

jQuery 1.4.2:

IE6

  • Immediate: ERROR
  • DOMready: ERROR
  • setTimeout: success

IE7

  • Immediate: ERROR
  • DOMready: success
  • setTimeout: success

jQuery 1.3.2:

IE6

  • Immediate: success
  • DOMready: success
  • setTimeout: success

IE7

  • Immediate: success
  • DOMready: success
  • setTimeout: success

comment:2 Changed 10 years ago by cowboy

And as I said in my code comments, I get slightly different results depending on whether all this code is in the head vs the body.

comment:3 Changed 10 years ago by miketaylr

For me, i get permission denied for all three (Immediate, DOMReady, and setTimeout) for both 1.3.2 and 1.4.x in IE7.

I get the same behavior in IE6 that "cowboy" describes--error, error, success w/ 1.4, and success, success, success in 1.3.2.

comment:6 Changed 10 years ago by Qwerios

Tested with:
Internet Explorer 6 (6.0.2900.5512.xpsp.080413-2111)
Windows XP SP3
VirtualBox 3.1.6

Getting some freaky results here...

JQUERY 1.4.2:

IE6 (1st time)

Immediate: ERROR
DOMready: success
setTimeout: success

(page reload after 1st try)
Immediate: ERROR
DOMready: ERROR
setTimeout: ERROR

(close browser, 2nd try)
Immediate: ERROR
DOMready: success
setTimeout: success

(reload after 2nd try)
Immediate: success
DOMready: success
setTimeout: success

(close browser, empty cache, 3rd try)
Immediate: ERROR
DOMready: ERROR
setTimeout: success

(reload after 3rd try)
Immediate: success
DOMready: success
setTimeout: success


JQUERY 1.3.2:

IE6 (1st time)

Immediate: success
DOMready: success
setTimeout: success

Every reload using 1.3.2 gives different results. I've had 1x ERROR, 2x ERROR, 3x ERROR and all success with no apparent pattern. But the first load after closing the browser is always 3x succes.

comment:7 Changed 10 years ago by cowboy

I wasn't using .splice correctly in my initial examples. I have since fixed my tests, but they still fail (albeit, in different places) for me in IE6 and IE7 (and work perfectly in IE8):

jQuery 1.4.2 http://benalman.com/code/test/jquery-142-document-domain-fixed.html

jQuery 1.3.2 http://benalman.com/code/test/jquery-132-document-domain-fixed.html

JQUERY 1.4.2:

IE6

Immediate: ERROR

DOMready: ERROR

setTimeout: ERROR

IE7

Immediate: ERROR

DOMready: success

setTimeout: success

JQUERY 1.3.2:

IE6

Immediate: ERROR

DOMready: ERROR

setTimeout: ERROR

IE7

Immediate: success

DOMready: success

setTimeout: success

comment:8 Changed 10 years ago by Qwerios

My results on the fixed test.

JQUERY 1.4.2:

IE6

Immediate: ERROR

DOMready: ERROR

setTimeout: ERROR

Reloading the page gives random results. There has to be some kind of race condition here...

JQUERY 1.3.2:

IE6

Immediate: success

DOMready: success

setTimeout: success

Reloads keep returning success

comment:9 Changed 10 years ago by cowboy

So, this seems to be a non-issue, but only when document.domain is set BEFORE jQuery is loaded! (thanks to @jaubourg for suggesting this approach)

jQuery 1.4.2 http://benalman.com/code/test/jquery-142-document-domain-before.html

jQuery 1.3.2 http://benalman.com/code/test/jquery-132-document-domain-before.html

Feel free to confirm!

comment:10 Changed 10 years ago by Qwerios

Verified on my IE6 test image. Both jQuery 1.3 and 1.4 tests work perfectly. Reloads work as well.

comment:11 Changed 10 years ago by dmethvin

Resolution: worksforme
Status: newclosed

I'll close this, sounds like there's a simple workaround.

Note: See TracTickets for help on using tickets.