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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

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


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