views:

27

answers:

1

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.

I have tried to do this many different ways and I can't seem to get it working.

$(documnet).ready(function() {
   $("<iframe src='../active_timer.html' id='iframeDialog' />").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.
});

active_timer.html:

<div id="dialog" style="overflow:hidden;">
    <p>
        <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 25px 0;"></span>
        You will be logged off in <span id="dialog-countdown"></span> seconds.
    </p>
    <p>Do you want to continue your session?</p>
</div>
A: 

When it loads, active_timer.html should pass a reference of the DOM element within active_timer.html to its parent.

function onLoad() {
   window.opener.childCountdown = document.getElementById("dialog-countdown");
}

In the parent:

var $countdown = $(childCountdown);
Jerome
could you maybe elaberate a bit more?
Randall Kwiatkowski
example code added
Jerome