javascript - Update parent value every time iframe reloads with iframe value -
i have page iframe , want update value in parent each time iframe loads form submit in iframe. code in parent :
<div id="updfield" style="display: block; float: left; margin: 12px 0px 0px 20px; width: 300px; font-size: 14px; color: #cc0000;"> test update field </div> this jquery in iframe:
$(window).on('load', function() { $("#updfield", window.parent.document).text("<?php echo $dupdate; ?>"); }); when first time iframe loads, parent div changes show value of $dupdate. if submit form in iframe changes $dupdate value, parent div not update. want parent div update each time iframe loads. assistance appreciated.
update:
ok, here's full, working code. sorry errors earlier. same idea. parent keeps track of child load events , reaches in , gets value want div somewhere.
two files: blah.html , childblah.html.
blah.html
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("#myframe").on("load", function () { var infocontainer = $("#myframe").contents().find("#somediv"); if (infocontainer!=null) $("#updfield").text(infocontainer.text()); }); }); </script> </head> <body> <iframe id="myframe" src="childblah.html" > </iframe> <div id="updfield"> </div> </body> </html> childblah.html
<html> <head> </head> <body onload="settimeout(function(){document.location.href='childblah.html';},3000)"> <div id="somediv"> xxxxxxx<div id='dv' /> <script>var dt=new date();document.getelementbyid('dv').innerhtml=dt;</script> </div> </body> </html> you can content specified location if exists instead of having child write value.
Comments
Post a Comment