gpt4 book ai didi

jquery - 无法修改 iframe 的内容,怎么回事?

转载 作者:太空狗 更新时间:2023-10-29 13:20:29 25 4
gpt4 key购买 nike

我正在尝试修改 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>

最佳答案

请不要忘记跨域策略,否则将无法正常工作。

现场演示: 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!');
});
});​

关于jquery - 无法修改 iframe 的内容,怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11658011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com