原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://wintys.blog.51cto.com/425414/123303
作者: 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 onload="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

本文出自 “wintysのブログ” 博客,请务必保留此出处http://wintys.blog.51cto.com/425414/123303

Javascript获取IFrame内容(兼容IE&FF)的更多相关文章

  1. javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,

    javascript获取iframe框架中,加载的页面document对象 因为浏览器安全限制,对跨域访问的页面,其document对象无法读取.设置属性 function getDocument(i ...

  2. javascript 获取iframe里页面中元素值的方法 关于contentWindow和contentDocumen

    javascript 获取iframe里页面中元素值的方法 IE方法:document.frames['myFrame'].document.getElementById('test').value; ...

  3. JavaScript获取地址栏内容

    例如地址为:http://www.mazey.net/baby/blog/index.php?a=1&b=2#c var query = window.location.href; //htt ...

  4. javascript 获取iframe元素的方法

    javascript  获取iframe元素的方法 第一种: $("#IframeID").contents().find("div"); 第二种: $(win ...

  5. javascript 获取iframe中的dom

    太扯了,一个多小时都没搞定,获取不到iframe中的dom元素. <div id="one"> this is one </div> <div> ...

  6. JS/javaScript 获取div内容

    jquery: 例如<div id="abc"><a>内容</a></div>$("#abc").html(); ...

  7. JavaScript获取输入框内容

    html: <input name="money" type="number" placeholder="税前工资"><b ...

  8. 获取iframe 内容

    parent.$.find("iframe")[0].contentWindow.getvalue(); h.find("iframe")[0].content ...

  9. layer获取iframe内容

    var layer1 = function() { layer.open({ type: 2, title: '标题', maxmin: false, area: ['780px', '600px'] ...

随机推荐

  1. resttemplate 文件上传 上传文件

    springmvc RestTemplate文件上传 RestTemplate上传文件总结

  2. WebRTC 源码分析(五):安卓 P2P 连接过程和 DataChannel 使用

    从本篇起,我们将迈入新的领域:网络传输.首先我们看看 P2P 连接的建立过程,以及 DataChannel 的使用,最终我们会利用 DataChannel 实现一个 P2P 的文字聊天功能. P2P ...

  3. 12 extremely useful hacks for JavaScript

    In this post I will share 12 extremely useful hacks for JavaScript. These hacks reduce the code and ...

  4. C# 最全的系统帮助类

    using System;using System.Collections;using System.Collections.Generic;using System.Configuration;us ...

  5. tensorflow 模型前向传播 保存ckpt tensorbard查看 ckpt转pb pb 转snpe dlc 实例

    参考: TensorFlow 自定义模型导出:将 .ckpt 格式转化为 .pb 格式 TensorFlow 模型保存与恢复 snpe tensorflow 模型前向传播 保存ckpt  tensor ...

  6. (原创)Linux下一定要4字节地址对齐操作

    Linux下一定要4字节地址对齐操作:“血”的教训,一定不要忘记!!! 当然不仅仅是Linux下,所有的32位机都应该如此!!!

  7. C# 初学

    突然对C#充满了兴趣,于是兴致勃勃的折腾起来. 下面是折腾的过程: IDE,我选择了vs2017,不过这货的安装选项略多,对于新手来说各种坑.无论如何,选择”.NET桌面开发”即可,其他的全部留空. ...

  8. Linux 安装 MongoDB数据库

    1下载: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.7.tgz (下载较慢) 2.安装: mv mongodb-li ...

  9. JDBC是什么?

    JDBC代表Java数据库连接(Java Database Connectivity),它是用于Java编程语言和数据库之间的数据库无关连接的标准Java API,换句话说:JDBC是用于在Java语 ...

  10. e739. 创建一个标签组件

    // The text is left-justified and vertically centered JLabel label = new JLabel("Text Label&quo ...