Reputation: 13
Perhaps this is a bug, but I cannot access an outer document from an iframe with jquery (IE7).
here a very simple example:
top document:
<html>
<head>
</head>
<body>
<iframe src="test2.html" id="UserIFrame" name="UserIFrame">
</body>
</html>
and child iframe:
<html>
<head>
<script type="text/javascript" src="styles/genevadesign_jquery-1.4.1.js"></script>
<script type="text/javascript">
function doit(){
$('body',top.document).append($('#test'));
$('#test',top.document).fadeIn(300);
}
</script>
</head>
<body>
<div id="test">test</div>
<input type="button" onclick="doit();"/>
</body>
</html>
As you can see, I try to access the top document from the inner frame like this:
$('body', top.document).append($('#test'));
But this does not work in IE7 "Invalid Argument". It works within the same document, but as soon as I refer another document it stops working.
PS. Gecko Browser can handle this. Just IE7 so far is not able to do so.
Upvotes: 1
Views: 3030
Reputation: 4320
The problem arises only in IE, and stems from the inability to create nodes and move nodes between the windows (which is surprisingly a good approach).
Consider the following example:
$("<iframe/>").append("<div/>");
In IE7 this will cause an error - as the element should have been created using iframe.ownerWindow.document
, and not with document.createElement
method, or window.ownerDocument.createElement
method. And it's happening in every DOM manipulation methods. IE7 also doesn't support importNode
/ adoptNode
methods.
So that leaves creating objects via JS and manipulating, yay!
Upvotes: 4