我正在尝试修改 iframe 的内容,但它不起作用。
这是我的 main.html
<html>
<head><title>Main page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<h3>Main page</h3>
<iframe src="ifr.htm" id="ifr" name="ifr"></iframe>
</body>
<script>
$(document).ready(function(){
$('#ifr').load(function(){
$('#ifr').contents().find('body').html('Hey, i`ve changed content of <body>! Yay!!!');
});
});
</script>
</html>
这是我的 ifr.htm
<html>
<head><title>Iframe page</title></head>
<body>
Content to be displayed in iframe ...
</body>
</html>
请不要忘记cross-domain
政策,不然不行。
现场演示: http://jsfiddle.net/oscarj24/wTWjF/
(只是要知道,我没有使用 404 页面,看看)
尝试这个:
$(document).ready(function(){
$('#ifr').ready(function(){
$(this).contents().find('body').html('Hey, I have changed the body content yay!');
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)