Note that there are some explanatory texts on larger screens.

plurals
  1. POCaching a reference to an element in an iframe with jquery
    primarykey
    data
    text
    <p>I am using a jquery dialog that uses an iframe to let the user know there session is about to expire. I would like to update this dialog every second with a countdown, thus I would like to cache a reference to the countdown element so we don't have to query the DOM for it each second.</p> <p>I have tried to do this many different ways and I can't seem to get it working.</p> <pre><code>$(documnet).ready(function() { $("&lt;iframe src='../active_timer.html' id='iframeDialog' /&gt;").dialog({ autoOpen: false, title: "Your session is about to expire!", modal: true, width: 400, height: 200, closeOnEscape: false, draggable: false, resizable: false, buttons: { "Yes, Keep Working": function(){ $(this).dialog("close"); }, "No, Logoff": function(){ //log user out } } }); // cache a reference to the countdown element. // these below don't cache the reference I have tried them all. var $countdown = $("#iframeDialog").contents().find("#dialog-countdown"); var $countdown = $("#dialog-countdown", window.child); var $countdown = $("#dialog-countdown", $('iframe').get(0).contentDocument); //this is where I update the #dialog-countdown every second after the reference is made. }); </code></pre> <p>active_timer.html:</p> <pre><code>&lt;div id="dialog" style="overflow:hidden;"&gt; &lt;p&gt; &lt;span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 25px 0;"&gt;&lt;/span&gt; You will be logged off in &lt;span id="dialog-countdown"&gt;&lt;/span&gt; seconds. &lt;/p&gt; &lt;p&gt;Do you want to continue your session?&lt;/p&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload