4

The following code throws a Permission Denied error in IE, citing jQuery (1.6.2) line 6244 Char:2:

function addAgreement() {
    var url = window.location.toString();
    var pieces = url.split('/');
    var site_url = url.replace(pieces[pieces.length -1], '');
    $('.login').append('<div id="dialog"></div>');
    $('#dialog').load(site_url + '?page_id=443');
}

$('#dialog').dialog({
    width: 800,
    position: 'top',
    modal: true,
    buttons: {
        "Agree": function() { 
            agreed = true;
            var val = $('#registerform').attr('action') + '&agreed=1';
            $('#registerform').attr('action', val);
            $(this).dialog("close");
            $('#registerform').trigger('submit');
        }, 
        "Disagree": function() { 
            agreed = false;
            $(this).dialog("close"); 
        } 
    }
});

It works in Firefox — is this something to do with same origin policy? jQuery is being served by Google CDN.

UPDATE The content being loaded is a WordPress page which also contains includes for cufon-yui.js (served locally). I have tried serving jQuery locally too (i.e not from the Google CDN) and this made no difference.

UPDATE 2 Removing the following script tags from the loaded page stops the error from appearing.

<script type='text/javascript' src='<?php echo bloginfo('template_url') ?>/inc/js/cufon-yui.js'></script> 
<script type='text/javascript' src='<?php echo bloginfo('template_url') ?>/inc/js/path/to/font.js'></script>
<script type='text/javascript'>
Cufon.replace('#page')('.title');
</script> 
Antti29
  • 2,953
  • 12
  • 34
  • 36
codecowboy
  • 9,835
  • 18
  • 79
  • 134
  • 1
    possible duplicate of [jQuery load() throws "permission denied" error in IE](http://stackoverflow.com/questions/1954740/jquery-load-throws-permission-denied-error-in-ie) – redsquare Sep 26 '11 at 14:06
  • The content being loaded in the load call is on the same subdomain as the calling page so I'm not sure if that is it. – codecowboy Sep 26 '11 at 14:19
  • 1
    It is not a same domain issue. Is the html being returned valid html, meaning, no run-away attribute strings(missing trailing quote) and tags are opened and closed properly? also, are you positive that the code only fails when this code is included? There is a bug in 1.6.2 that causes IE to fail when a background image is on the body tag. – Kevin B Sep 26 '11 at 14:47
  • Thanks. It looks like the content being loaded is NOT valid html and does not contain HTML, BODY, HEAD tags etc.Removing the load() call DOES clear the error. – codecowboy Sep 26 '11 at 15:06
  • However, even if I ensure the markup being loaded is valid, I'm still getting the error :( – codecowboy Sep 26 '11 at 15:28
  • 1
    the html body and head will be removed from the resulting html when you use .load() because those tags already exist on the page requesting the html. that wouldn't cause this error. – Kevin B Sep 26 '11 at 15:32
  • Have added a further update which seems to pinpoint cufon-yui as the cause, though not sure why. – codecowboy Sep 26 '11 at 16:22

1 Answers1

2

For AJAX requests, www. is seen as a sub-domain and breaks the same-origin policy for the xmlhttprequestobject. Make sure the domain in your AJAX request matches the domain of the page and your javascript file.

Lakshmana Kumar D
  • 2,205
  • 1
  • 13
  • 10