Access parent document from dynamic iframe using j

2019-03-03 13:31发布

问题:

This question is continuation of this question. I use the following code to append the dynamic <iframe> to the document.

var _hf_iFrame = document.createElement("iframe");
_hf_iFrame.setAttribute("id", "_hf_iFrame");
_hf_iFrame.setAttribute("name", "_hf_iFrame");
_hf_iFrame.setAttribute("allow-transparency", true);
_hf_iFrame.setAttribute("style", "height: 354px; width: 445px; border: 0; top: 23%; position: fixed; left:0; overflow: show; background:transparent;");
document.body.appendChild(_hf_iFrame);
_hf_iFrame.setAttribute("src", "javascript:false");

var myContent = '<!DOCTYPE html>'
+ '<html><head><title>Helpflip</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script><script type="text/javascript" src="http://somedomain.com/js/core.js"></script></head>'
+ '<body style="margin: 0px;"></body></html>';

_hf_iFrame.contentWindow.document.open('text/html', 'replace');
_hf_iFrame.contentWindow.document.write(myContent);
_hf_iFrame.contentWindow.document.close();

When the <iframe> has loaded, I am trying to animate it using the following code

$('#_hf_iFrame', top.document).animate({
      'margin-left': '-400px'
   }, 300).animate({
      'margin-left': '-380px'
   }, 150).animate({
      'margin-left': '-393px'
}, 100);

This works fine on Firefox, Chrome and on Safari. IE 9 throws Access Denied on line $('#_hf_iFrame', top.document)

Does the problem of cross domain still apply?

Thanks in advance.