0

iframe を使用する jquery ダイアログを使用して、セッションの有効期限が切れようとしていることをユーザーに知らせます。このダイアログを毎秒カウントダウンで更新したいので、カウントダウン要素への参照をキャッシュして、毎秒 DOM にクエリを実行する必要がないようにします。

私はこれをさまざまな方法でやろうとしましたが、うまくいかないようです。

$(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>
4

1 に答える 1

0

ロード時に、active_timer.html は、active_timer.html 内の DOM 要素の参照をその親に渡す必要があります。

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

親で:

var $countdown = $(childCountdown);
于 2010-09-03T18:17:38.903 に答える