在Web开发时,很多时候会遇到一个问题。我在一个页面嵌入了iframe,并且我想获得这个iframe页面某个元素的值。那么该如何实现这个需求呢?
先来看下演示:
效果演示
iframe1中文本框的值:
在IE下操作IFrame内容的代码:
1 |
document.frames["MyIFrame"].document.getElementById("s").style.color="blue"; |
但是这在Firefox下无效。所以,想到在Firefox下用FireBug来调试。经过调试发现在Firefox下可用以下代码来实现:
1 |
document.getElementById("MyIFrame").contentDocument.getElementById("s").style.color="blue"; |
demo代码:
01 |
<div><iframe name="frame1" id="frame1" src="frm.html" frameborder="1"height="60"></iframe></div> |
03 |
<p>iframe1中文本框的值:<input type="button" name="Submit"value="getValue" onclick="getValue()" /></p> |
05 |
<script type="text/javascript"> |
08 |
var ofrm1 = document.getElementById("frame1").document; |
11 |
ofrm1 = document.getElementById("frame1").contentWindow.document; |
12 |
var ff = ofrm1.getElementById("txt1").value; |
13 |
alert("firefox/chrome取值结果为:" + ff); |
17 |
var ie = document.frames["frame1"].document.getElementById("txt1").value; |
18 |
alert("ie取值结果为:" + ie); |
iframe页面代码:
07 |
<input id="txt1" name="txt1" type="text" value="欢迎访问www.nowamagic.net" /> |
- Jquery 方式获取 iframe Dom元素
Jquery 方式获取 iframe Dom元素 測试页面代码: <html> <head> <title>jquery方式,訪问iframe页面dom元素& ...
- 页面中获取 iframe 中的值
3.页面中获取 iframe 中的值 var obj=document.getElementsByClassName(".ke-edit-iframe").contentWindo ...
- 父页面内获取获取iframe内的变量或者是获取iframe内的值
前提:页面不可跨域访问,必须同一域名下,否则返回值为空 父页面 <!DOCTYPE html> <html lang="en"> <head> ...
- javascript_获取iframe框架中元素节点的属性值
1. DOM:文档对象模型 [window 对象] 它是一个顶层对象,而不是另一个对象的属性即浏览器的窗口. [document 对象] 该对象是window和frames对象的一个属性,是显示于窗口 ...
- 在iframe中获取本iframe DOM引用
window.frameElement 获取本iframe DOM window.frameElement.contentDocument.getElementById('id') 获取这个ifram ...
- 页面间(窗口间)的取值赋值及获取iframe下的window对象
①同一个窗口中,获取某个iframe的信息 <body> <iframe id="PAID" name="PA" src="Item ...
- jquery获取iframe中的dom对象
父窗口中操作iframe:$(window.frames["iframeChild"].document) //假如iframe的id为iframeChild 在子窗口中操作 ...
- javascript 获取iframe里页面中元素值的方法 关于contentWindow和contentDocumen
javascript 获取iframe里页面中元素值的方法 IE方法:document.frames['myFrame'].document.getElementById('test').value; ...
- vue3 template refs dom的引用、组件的引用、获取子组件的值
介绍 通过 ref() 还可以引用页面上的元素或组件. DOM 的引用 <template> <div> <h3 ref="h3Ref">Tem ...
随机推荐
- BigData--hadoop集群搭建之hbase安装
之前在hadoop-2.7.3 基础上搭建hbase 详情请见:https://www.cnblogs.com/aronyao/p/hadoop.html 基础条件:先配置完成zookeeper 准备 ...
- nginx配置SSL证书/强制跳转与非强制跳转
支持强制跳转HTTPS server { listen 80; server_name www.test.com; rewrite ^(.*)$ https://${server_name}$1 pe ...
- Spark Streaming实时处理应用
1 框架一览 事件处理的架构图如下所示. 2 优化总结 当我们第一次部署整个方案时,kafka和flume组件都执行得非常好,但是spark streaming应用需要花费4-8分钟来处理单个 ...
- 15 GIL 全局解释器锁 C语言解决 top ps
1.GIL 全局解释器锁:保证同一时刻只有一个线程在运行. 什么是全局解释器锁GIL(Global Interpreter Lock) Python代码的执行由Python 虚拟机(也叫解释器主循环, ...
- LeetCode:24. Swap Nodes in Pairs(Medium)
1. 原题链接 https://leetcode.com/problems/swap-nodes-in-pairs/description/ 2. 题目要求 给定一个链表,交换相邻的两个结点.已经交换 ...
- 洛谷P1090 合并果子
合并果子 题目链接 这个只能用于结构体中 struct item { int val; friend bool operator < (item a,item b) { return a.val ...
- 听雷哥浅谈Redis
Linux下安装redis 1.下载源码,解压缩后编译源码. $ wget http://download.redis.io/releases/redis-2.8.3.tar.gz $ tar xzf ...
- android开源项目之OTTO事件总线(二)官方demo解说
官方demo见 https://github.com/square/otto 注意自己该编译版本为2.3以上,默认的1.6不支持match_parent属性,导致布局文件出错. 另外需要手动添加an ...
- [转]Visual Studio 项目类型 GUID 清单
转自:https://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs Complete li ...
- Qt QLabel 播放GIF动画
很久以前用过,不过慢慢的不用了,就慢慢的忘记了,今天拾起来,记录一下,以后用的时候可以翻一下 QLabel播放GIF动画其实很简单 第一步,需要包含头文件,Qt播放GIF动画,我使用的是QMovie类 ...