Monday, 15 April 2013

php - Javascript setinterval() sets variables to null after the first run of the function -



php - Javascript setinterval() sets variables to null after the first run of the function -

i trying output of iframe b in page a div in page a. wrote next code:

function funcexec() { todornamespace = {}; todornamespace.nan = true; todornamespace.i = 0; todornamespace.div = document.getelementbyid("render_frame"); todornamespace.iframe = document.getelementbyid('iframe_exec'); var patharray = window.location.href.split('/'); var protocol = patharray[0]; var host = patharray[2]; var url = 'http://' + host; var src = url + '?q=exec_command'; // div.appendchild(iframe); todornamespace.iframe.setattribute("src", src); var interval = setinterval(function() { myprint() }, 200, this); function myprint() { var text; var body = todornamespace.iframe.contentdocument.body; if (body != null) { text = body.innerhtml; } if (text != null) { var logs = text.split("\n"); } if (logs != undefined) { if (logs[todornamespace.i] != "</pre>nan" && logs[todornamespace.i] != undefined) { todornamespace.div.innerhtml = todornamespace.div.innerhtml + logs[todornamespace.i] + "</br>"; todornamespace.i++; } else if (logs[todornamespace.i] == "</pre>nan") { todornamespace.div.innerhtml = todornamespace.div.innerhtml + "</pre>"; clearinterval(interval); } else { } } } }

the problem prints first line iframe , dies error :

uncaught typeerror: cannot read property 'body' of null @ line 19

i checked debugger, after sec start of function myprint() variables todornamespace.iframe , todornamespace.div becoming null. why happening , can prepare reading problem? iframe b php page, printing output @ rate 2-3 lines per sec php code:

while ( @ ob_end_flush () ) ; $proc = popen ( "mybashcommand", 'r' ); echo '<pre>'; while ( ! feof ( $proc ) ) { echo fread ( $proc, 4096 ); @ flush (); } echo '</pre>'; @ flush (); echo 'nan';

which suggests cannot wait until page generated 1 time , print output, need in "real time", hence iteration setinterval text iframe. ideas how implement it?

javascript php html scope setinterval

No comments:

Post a Comment