开发者

Change HTML of an iFrame with jQuery?

开发者 https://www.devze.com 2023-03-04 20:04 出处:网络
Is there a way to manipulat开发者_Go百科e the HTML of an iframe that is from the same domain using jQuery?

Is there a way to manipulat开发者_Go百科e the HTML of an iframe that is from the same domain using jQuery?

Thanks for the help.


You'll have to parse the iframe content.

$("#frameid").contents().find("div").html('My html');

More here : http://api.jquery.com/contents/


You can use contents() to manipulate the contents of the iframe.

$("#frameDemo").contents().find("div").html("new HTML content goes here");


Here is an example from the jQuery documentation:

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <iframe src="http://api.jquery.com/" width="80%" height="600" id='frameDemo'></iframe> 
<script>$("#frameDemo").contents().find("a").css("background-color","#BADA55");</script>

</body>
</html>


If you want to change the contents inside the <body> tag of the iframe, you can use this code:

$("#iframe_id").contents().find("body").html('my_new_content');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号