用JS操作FRAME中的IFRAME及其內容的實現代碼
更新時間:2008年07月26日 13:17:31 作者:
一直都需要這樣的東西,發(fā)現了這個好東西,一定要研究下
問:想通過在地址欄輸入一段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"; 大家試試就知道了。
主頁面.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"; 大家試試就知道了。
相關文章
JavaScript之Date_動力節(jié)點Java學院整理
在JavaScript中,Date對象用來表示日期和時間。下面給大家介紹js中的date,需要的朋友參考下吧2017-06-06