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

Javascript
Mootools 1.2教程 排序类和方法简介
Mootools 1.2 手风琴(Accordion)教程
Mootools 1.2教程 类(一)
Mootools 1.2教程 Tooltips
Mootools 1.2教程 选项卡效果(Tabs)
Mootools 1.2教程(21):类(二)
Mootools 1.2教程 同时进行多个形变动画
Mootools 1.2教程 滑动效果(Slide)
不安全的常用的js写法
javascript 检测浏览器类型和版本的代码
javascript 弹出层居中效果的制作
javascript 遮照层效果
Javascript createElement和innerHTML增加页面元素的性能对比
颜色快速采集器javascript代码
var与Javascript变量隐式声明
javascript 面向对象编程 万物皆对象
jQuery 事件队列调整方法
JavaScript switch case 的用法实例[范围]
控制input的CSS但不影响CheckBox以及Radio的样式
ext 同步和异步示例代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 356 ::
收藏到网摘: 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"; 大家试试就知道了。