原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。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. UI设计 - 首页(主页)的任务

    什么是首页 首页,又可以叫主页,是我们的网站或者APP的主要页面,它是我们接触的第一个页面(如果不包含闪屏页和登陆页的话). 特点 首页是一个开始的地方,我们开始真正接触网站提供给我们的内容. 首页是 ...

  2. im ui框架调研,对比

    1, https://github.com/jpush/aurora-imui 极光的 支持 Android/iOS/RN 提供了消息列表.输入视图 功能不多, 2,https://github.co ...

  3. XmlnsDefinition for a Cool Namespace Mapping

    In XAML, when you want to reference a CLR type, you have to add a namespace mapping that maps the XM ...

  4. C++标准转换运算符static_cast

    该运算符把expression转换为type-id类型,但没有运行时类型检查来保证转换的安全性.   中文名 暂无 外文名 static_cast 分    类 强制类型转换 类    型 C++ s ...

  5. python-下载百度图片到本地

    import requests import os def getManyPages(keyword,pages): params=[] for i in range(30,30*pages+30,3 ...

  6. Java如何暂停线程一段时间?

    在Java编程中,如何暂停线程一段时间? 以下示例显示如何通过创建sleepThread()方法来暂停线程一段时间. package com.yiibai; public class Suspendi ...

  7. Java如何监视线程的状态?

    在Java编程中,如何监视线程的状态? 以下示例演示如何通过扩展Thread类并使用currentThread.getName()方法来监视线程的状态. package com.yiibai; cla ...

  8. e797. 显示JSlider的标记

    The slider supports two levels of tick marks, major and minor. Typically, the minor tick-mark spacin ...

  9. Unity GUI(uGUI)使用心得与性能总结

    Unity GUI(uGUI)使用心得与性能总结 作者 kingshijie 关注 2015.09.26 15:35 字数 3686 阅读 28031评论 10喜欢 49 背景和目的 小哈接触Unit ...

  10. 本地没问题 服务器 提示 Server Error in '/' Application

    一. 先用本机的 IIS 测试,不要用 VS 内附的 Web server,並配置 <customErrors mode="Off"/>,以將真實的錯誤原因顯示出來,看 ...