从IFrame文档获取标题 [英] Get title from IFrame document
本文介绍了从IFrame文档获取标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
< div id =main-content>
< script>
document.title = document.getElementById(main-content-iframe)。contentDocument.title;
< / script>
< / div>
这不起作用,我做错了什么?
< / p> div id =main-content>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js>< / script>
< script>
$(iframe).on('load',function(){
document.title = document.getElementById(main-content-iframe)。contentDocument.title;
});
< / script>
This is my code:
<div id="main-content">
<script>
document.title = document.getElementById("main-content-iframe").contentDocument.title;
</script>
<iframe name="cstage" src="home.html" width="100%" height="100%" id="main-content-iframe" frameborder="0" onload="document.title=parent.frames['cframe'].document.title;">If you're seeing this message, it means IFrames are not supported; Please enable IFrames or upgrade to a compatible browser that supports IFrames.</iframe>
</div>
It's not working, what am I doing wrong?
解决方案
You need to check that the iframe is loaded.
<div id="main-content">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<iframe name="cstage" src="home.html" width="100%" height="100%" id="main-content-iframe" frameborder="0" onload="document.title=parent.frames['cframe'].document.title;">If you're seeing this message, it means IFrames are not supported; Please enable IFrames or upgrade to a compatible browser that supports IFrames.</iframe>
<script>
$( "iframe" ).on('load',function() {
document.title = document.getElementById("main-content-iframe").contentDocument.title;
});
</script>
这篇关于从IFrame文档获取标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文