JS iFrame to load slowly how to solve

Often dynamically added iframe in the project, and then to add the iframe related operations, sometimes encounter iframe loads slowly, what causes it, how to solve it? With this question in this article together to learn, to find the answer!

 

aaa.html

 

<HTML>

<HEAD>

<TITLE>aaa</TITLE>

</HEAD>

<BODY>

<IFRAME src="bbb.html" name=bbb width="100%" height="190"> </IFRAME>

<INPUT type="button" value="显示text控件值" onclick="alert(bbb.document.all.txt.value)">

<SCRIPT LANGUAGE="JavaScript">

alert(bbb.document.all.txt.value);

</SCRIPT>

</BODY>

</HTML>

 

 

 

 

bbb.html

 

<HTML>

<HEAD>

<TITLE>bbb</TITLE>

</HEAD>

<BODY>

<input type=text name=txt value="guoguo">

</BODY>

</HTML>

 

 

problem:

Implementation of the above aaa.html found that the value of the code directly alert did not play out, and click on the button, but can play its value. Note To run on the server.

analysis:

When the page loads encountered iframe directly jump, load following, and then come back loaded iframe, of course, can be understood as encountered iframe has opened a thread to load the iframe, but because it involves a new IO operations more consumption when so loaded iframe or late js code to the bottom of the page execution, hence the above problems.

Solution:

Plus delay (specifically how long the delay may be based on a personal experience) in js code, so as to ensure the normal iframe objects have been.

 

<SCRIPT LANGUAGE="JavaScript">

setTimeout("alert(bbb.document.all.txt.value)",1500);

</SCRIPT>

 

 

Conclusion: When a page contains a iframe, if we want to manipulate objects in an iframe through js, we must wait until after the iframe is loaded again, otherwise not get the desired object.

 

Guess you like

Origin www.cnblogs.com/qcjdp/p/12050375.html