Reputation: 17279
I have a file called iframe.html, which contains the code to for a image slideshow or etc. The code is somewhat like
<html>
<head>
</head>
<body>
<iframe id="i1" src="test.html"></iframe>
<div id='i2'></div>
</body>
</html>
i want to get content of iframe and set i2
with that in jQuery such as:
$(document).ready(){
var i1= $('#i1').contents();
$('#i2').html( i1 );
}
that do not correct, how to resolve that?
Upvotes: 1
Views: 728
Reputation:
If you look at the console, you'll probably see a syntax error.
Add the closing parenthese after your $(document).ready
and the function
keyword, like this:
$(document).ready(function() { // function here
var i1= $('#i1').contents();
$('#i2').html( i1 );
}); // closing parenthese here
Upvotes: 1
Reputation: 148514
Change : <iframe id="i1" src="test.html"></iframe>
to
<iframe id="i1" src="test.html" onload='aaa();'></iframe>
And add :
function aaa(){
var a= $('#i1').contents().find("html").html()
$('#i2').html( a );
}
Upvotes: 1