用JS操作FRAME中的IFRAME及其內容的實現代碼

來源:互聯網
上載者:User

問:想通過在地址欄輸入一段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"; 大家試試就知道了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.