0

PHP関数を呼び出してファイルの変更時間をチェックするAjaxコールバック関数があります。タイマーを使用して50秒ごとに実行します。

    <script type="text/javascript">
    setInterval("_checkPopUpUpdate()", 50000); //50 seconds
    </script>

    function _checkPopUpUpdate()
    {
        var callback=new Object();
        callback.success=this.onExternalSuccess;
        callback.failure=this.onExternalFailure;
        YAHOO.util.Connect.asyncRequest('GET','/ci/ajaxCustom/ajaxCheckPopupUpdate',callback);
};

PHP 関数は、ファイルの変更時間が最初のロード セッション時間と異なるかどうかをチェックします。

     $announcement_Popup_Path = HTMLROOT . $this->data['attrs']['file_path'];
  // Call model function

 if($this->data['attrs']['file_path'] !== '' && file_exists($announcement_Popup_Path))
 {
     //When the announcement content load, it always stores the modified time into session
         $this->CI->load->model('custom/checkupdate_model');
           $firstloadTime = filemtime($announcement_Popup_Path);
     $this->CI->checkupdate_model->store_AnnouncementPopupSession($firstloadTime);
     //$this->data['Popup'] = file_get_contents($announcement_Popup_Path);
 }    

        function store_AnnouncementPopupSession ($popupTime)
    {
 $sessionPopupTime =array("annoucementPopUp"=> $popupTime);
 $this->session->setSessionData($sessionPopupTime);
    }

     function announcement_pop()
    {
 $file_path='/euf/assets/announcements/pop_up_announcement.html';
 $announcement_Popup_Path = HTMLROOT . $file_path;
 if(file_exists($announcement_Popup_Path)) {
     $currentAnnouncementPopUpTime = filemtime($announcement_Popup_Path);
     $oldannouncementPopupTime = $this->session->getSessionData("annoucementPopUp");

     if($currentAnnouncementPopUpTime !=$oldannouncementPopupTime) {
  //comparing the content and update the time, when they are different,  send back update content
  $this->store_AnnouncementPopupSession($currentAnnouncementPopUpTime);
  //echo $currentAnnouncementPopUpTime;
  echo $file_path;
     }
     else {
  echo "no update";
     }
 }
    }

ファイルの変更時刻が変更されると、ajax コールバックに戻り、Web サーバーの HTML コンテンツを取得して、アナウンス ポップアップ ウィンドウをポップアップします。

    function onExternalSuccess (o){
    if(o.responseText!==undefined)
    {
 var str=o.responseText;


     if(str !== 'no update') // Then pop up.
     {
  L=screen.width-200;
  T=screen.height;
  popup=window.open(str," ",'alwaysRaised=yes,status=no,toolbar=no,location=no,menubar=no,directories=no,resizable=no,scrollbars=no,height=150,width=364,left="+L+",top="+T');
  //popup=window.open(str,"",'alwaysRaised=yes,status=no,toolbar=no,location=no,menubar=no,directories=no,resizable=no,scrollbars=no,height=100,width=330');
  for (i=0;i<200;i++)
  {
      T=T-1;
      popup.moveTo(L,T);
  }
     }
    }
};

Firefox と Chrome では問題なく動作しますが、IE7 では少しバグがあり、ポップアップが表示されないことがあります。

<html>
    <head>
 <title>Internal alert</title>
 <link rel="stylesheet" type="text/css" href="/euf/assets/css/pop_up_ann.css" media="screen, projection" />
 <script type="text/javascript">
    var howLong = 50000; //5 minutes, 1 seconds = 1000 milliseconds.
    t = null;
    function closeMe(){
    t = setTimeout("self.close()",howLong);
    }
      </script>
    </head>
    <body onLoad="closeMe();self.focus();">
 <div id="cs_popup">
        <div class="popup_rounded-corner-top">
            <div id="popup_ann">
                <div id="popup_ann_title">IE7 pop-up EMEA test close </div>
                <div id="popup_ann_from"> PLC team - 05/01/2011 at 12:10</div>
            <div id="popup_ann_content">
            Something has changed in the<em>&quot;Alerts&quot;</em> section of S4S since your last visit.
            Make sure you go there as soon as you can to be informed about the current situation.
            </div>
            </div>
        </div>
        <div class="popup_rounded-corner-bottom"></div>
    </div>
    </body>
</html>

ここで私が抱えている主な問題は、セルフクローズ機能です。ポップアップ ウィンドウと Web サイトも閉じます。ヒントはありますか?また、ポップアップ通知の論理構造全体が正しいかどうかもわかりませんが、とにかくありますか? ありがとう

4

1 に答える 1

1

このようなアナウンスのためにポップアップ ウィンドウを開くことは、ポップアップ ブロッカーを実行している人にとっては問題になる可能性があります。ポップアップ ブロッカーは通常、何かをクリックするなど、ユーザーが開始したイベントに応答してポップアップを表示することしか許可しません。メッセージを承認する必要がある場合は、ポップアップをモーダルに表示する (つまり、ページの残りの部分を半透明の div でマスクする) こともできるインライン ポップアップを使用することをお勧めします。

self.close() の使用は、ユーザーが開いた元のウィンドウ/タブを閉じるべきではありません。「開いた」ものだけを閉じる必要があるため、そこで何が起こっているのかわかりません。すべてを教えてくれました:)別のアプローチは、ウィンドウ自体を閉じるのではなく、ウィンドウを閉じるようにポップアップ関数を変更することです。

// open popup ... then set timeout to close it
var popupDelay = 50000;
setTimeout(function() {
  popup.close();
}, popupDelay);

これは少しうまくいくかもしれませんが、確かではありません。しかし、長い目で見れば、ポップアップを避け、代わりに何かインラインを使用することを強くお勧めします。

于 2011-01-05T13:28:07.453 に答える