在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 ...
随机推荐
- ABAP CDS ON HANA-(8)算術式
Arithmetic expression in CDS View Allowed Arithmetic operators in CDS view. CDS View- @AbapCatalog.s ...
- scrapy编写爬虫的时候出现缺少win32api
环境:python3.6 工具:pycharm2017.3 scrapy fetch http://www.baidu.com ModuleNotFoundError: No module named ...
- XML文件中关键字自动提示和不全配置
一.获得mybatis-3-config.dtd.mybatis-3-mapper.dtd 这两个文件. 建立一个Maven的项目 在Pom.xml文件中的Mybatis jar包的下载设置(也可以从 ...
- 【转】odoo11新功能及绿色版汇总
昆山-Jeffery 11:34:00 ,odoo11 新功能: 评论:看到截图,感觉美工上又有所提高 官方的发布说明:https://www.odoo.com/nl_NL/page/odoo-11- ...
- 第5模块闯关Bootstrap
“行(row)”必须包含在 .container (固定宽度)或 .container-fluid (100% 宽度)中,以便为其赋予合适的排列(aligment)和内补(padding). 通过“行 ...
- Andrid 打印调用堆栈
public static void printCallStatck() { Throwable ex = new Throwable(); StackTraceElement[] stackElem ...
- stm32--FatFs调试过程(SPIFlash)
移植方法参见我的另一篇博客:<stm32--FatFs移植(SPIFlash)>. 本文仅记录在初次移植完成后,遇到的问题,和解决的过程. 调试记录: 问题1:f_open返回3,即磁盘没 ...
- SpringBoot学习:使用logback进行日志记录
项目下载地址:http://download.csdn.NET/detail/aqsunkai/9805821 (一)pom.xml文件中引入jar: <!-- https://mvnrepos ...
- iOS中如何根据UIView获取所在的UIViewController
原理 Responder Chain 事件的响应者链 大概的传递规则就是从视图顶层的UIView向下到UIViewController再到RootViewController再到Window最后到Ap ...
- Qt 建立带有子项目的工程
刚需,软件需要用到多个子项目 第一步 打开Qt新建子项目工程 如图 在此时鼠标右键,选着新建子项目如图 就是正常的新建项目的步骤,直接上图 完工,可以愉快的撸代码了