博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Javascript获取IFrame内容(兼容IE&FF)
阅读量:7107 次
发布时间:2019-06-28

本文共 894 字,大约阅读时间需要 2 分钟。

原创作品,允许转载,转载时请务必以超链接形式标明文章   、作者信息和本声明。否则将追究法律责任。
作者: Winty
时间: 2008-12-26
在网上找到在IE下操作IFrame内容的代码:
   
document.frames[
"MyIFrame"].document.getElementById(
"s").style.color=
"blue";
但是这在Firefox下无效。
所以,想到在Firefox下用FireBug来调试。经过调试发现在Firefox下可用以下代码来实现:
   
document.getElementById(
"MyIFrame").contentDocument.getElementById(
"s").style.color=
"blue";
详细代码如下:
TestIFrame.htm:
<html>
<head>
<script type=
"text/javascript">
function f(){
        
var doc;
        
if (document.all){
//IE
                doc = document.frames[
"MyIFrame"].document;
        }
else{
//Firefox    
                doc = document.getElementById(
"MyIFrame").contentDocument;
        }
        doc.getElementById(
"s").style.color=
"blue";
}
</script>
</head>
<body οnlοad=
"f()">
<iframe id = 
"MyIFrame" name = 
"MyIFrame" src = 
"MyIFrame.htm" width = 
"100" height=
"100">
</body>
</html>
MyIFrame.htm:
<
h1 id = "s" 
style
="color:red;" 
>内容
<
h1
>
附件内容:
1.TestIFrame.htm
2.MyIFrame.htm

本文出自 “” 博客,请务必保留此出处

你可能感兴趣的文章
谈谈对TCP、UDP、FTP、HTTP、Socket理解
查看>>
4.3 Verilog练习(3)
查看>>
其实都没变
查看>>
poj1011
查看>>
12、借助Jacob实现Java打印报表(Excel、Word)
查看>>
整除分块
查看>>
ACM-ICPC 2018 焦作赛区网络预赛
查看>>
API、ABI区别
查看>>
Ubuntu安装YCSB
查看>>
django 缓存、序列化、信号
查看>>
javascript的调试
查看>>
Error when loading the SDK 发现了以元素 'd:skin' 开头的无效内容。此处不应含有子元素...
查看>>
走过13,展望14----希望是个好东西
查看>>
不需手动锁表同步mysql数据库
查看>>
proxmox超融合私有云发布最新版本PVE 5.3
查看>>
使用tornado httpclient的异步库AsyncHTTPClient构建中转接口
查看>>
Skype for Business Server 2015-13-IISARR-1-部署
查看>>
回顾2013,展望2014
查看>>
来自新浪同学的学习及工作心得
查看>>
Windows Server 2012正式版RDS系列②
查看>>