当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用JS操作FRAME中的IFRAME及其内容的实现代码

Javascript
JS 参数传递的实际应用代码分析
prototype与jquery下Ajax实现的差别
用JS写的简单的计算器实现代码
javascript 数组操作实用技巧
JavaScript 中级笔记 第二章
JavaScript 中级笔记 第三章
JavaScript 中级笔记 第四章 闭包
JavaScript 中级笔记 第五章 面向对象的基础
Mootools 1.2教程 函数
Mootools 1.2教程 事件处理
通过Mootools 1.2来操纵HTML DOM元素
Mootools 1.2教程 设置和获取样式表属性
Mootools 1.2教程 输入过滤第一部分(数字)
Mootools 1.2教程 输入过滤第二部分(字符串)
Mootools 1.2教程 Fx.Tween的使用
Mootools 1.2教程 Fx.Morph、Fx选项和Fx事件
MooTools 1.2中的Drag.Move来实现拖放
Mootools 1.2教程 正则表达式
Mootools 1.2教程 定时器和哈希简介
Mootools 1.2教程 滚动条(Slider)

Javascript 中的 用JS操作FRAME中的IFRAME及其内容的实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 355 ::
收藏到网摘: n/a

一直都需要这样的东西,发现了这个好东西,一定要研究下 问:想通过在地址栏输入一段JS来设置一下页面里某个FRAME中的IFRAME的URL和里面某个TEXT的值,然后点击提交按钮。注意:页面是其它网站的,不要给出一些改动页面代码的答案。具体情况如下:
主页面.htm:
view plaincopy to clipboardprint?
<FRAMESET border=0 frameSpacing=0 frameBorder=0 cols=*,1005,*> <FRAME src="blank.html" frameBorder=0 noResize scrolling=no> <FRAMESET border=0 frameSpacing=0 rows=*,585,* frameBorder=0> <FRAME name=Frame1 src="http://.../blank.html" frameBorder=0 noResize scrolling=no> <FRAME name=primaryFrame src="http://.../main.jsp" frameBorder=0 noResize scrolling=no> <FRAME src="http://.../blank.html" frameBorder=0 noResize scrolling=no> </FRAMESET> <FRAME src="http://.../blank.html" frameBorder=0 noResize scrolling=no> </FRAMESET>
<FRAMESET border=0 frameSpacing=0 frameBorder=0 cols=*,1005,*> <FRAME src="blank.html" frameBorder=0 noResize scrolling=no> <FRAMESET border=0 frameSpacing=0 rows=*,585,* frameBorder=0> <FRAME name=Frame1 src="http://.../blank.html" frameBorder=0 noResize scrolling=no> <FRAME name=primaryFrame src="http://.../main.jsp" frameBorder=0 noResize scrolling=no> <FRAME src="http://.../blank.html" frameBorder=0 noResize scrolling=no> </FRAMESET> <FRAME src="http://.../blank.html" frameBorder=0 noResize scrolling=no> </FRAMESET> main.jsp :
<iframe id=chatFrame name=chatFrame src="http://.../a.jsp" ></iframe>
<iframe id=mainFrame name=mainFrame src="http://.../b.jsp" ></iframe>
要求:
1.当打开主页面后,在地址栏里输入一段JS,来改变mainFrame的src为http://.../c.jsp.
2.当打开主页面后,在地址栏里输入一段JS,来设置mainFrame此时的页面中name为"txt1"的文本框的值为"119",并点击其中name为"btn1"的按钮.
GOOGLE了一下,还真没找到现成的类似答案。于是自己试了试,试出了答案。相信对于再问同样问题的朋友,可以有所帮助。
1.javascript:frames("primaryFrame").document.mainFrame.location=http://.../c.jsp;
2.javascript:var a=frames("primaryFrame").document.mainFrame.document.getElementById("txt1").value="119";frames("primaryFrame").document.mainFrame.document.getElementById("btn1").click();
至于设置文本框为什么是var a=frames("primaryFrame").document.mainFrame.document.getElementById("txt1").value="119";而不是直接用frames("primaryFrame").document.mainFrame.document.getElementById("txt1").value="119"; 大家试试就知道了。