弹出窗口自动关闭功能;也关闭该网站

发布于 2024-10-10 14:38:34 字数 4168 浏览 2 评论 0原文

我有一个 Ajax 回调函数,它调用 PHP 函数检查文件修改时间。 我使用计时器每 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>

我这里遇到的主要问题是自关闭功能。它也会关闭我的弹出窗口和网站。有什么提示吗?另外,我不确定我的整个弹出公告逻辑结构是否正确,有吗?谢谢

I have an Ajax call back function which call to a PHP function check the file modified time.
I uses timer to execute it every 50 seconds.

    <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);
};

The PHP function checks whether the file modified time has different between the first load session time

     $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";
     }
 }
    }

When the file modifed time has changed, it will return to ajax call back and grab the HTML content in my web server to Pop up an annoucement pop up window.

    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);
  }
     }
    }
};

It works fine for Firefox and Chrome, however IE7 is a bit bugy, sometime the pop up does not come out.

<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>"Alerts"</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>

The main problem i have here it is self-close function. It close my pop up window and the website as well. Any hints? Also, i am not sure whether my whole pop up annoucement logical structure is correct, is there anyway? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花肆意 2024-10-17 14:38:34

对于运行弹出窗口阻止程序的人来说,打开这样的公告的弹出窗口可能会出现问题,这些程序通常只允许弹出窗口出现以响应用户启动的事件(例如单击某些内容)。更好的方法是使用内联弹出窗口,如果您需要他们确认您的消息,它还可以让您有机会以模式方式显示弹出窗口(即用半透明 div 屏蔽页面的其余部分)。

使用 self.close() 不应关闭用户打开的原始窗口/选项卡,它应该只关闭已“打开”的内容,所以我不确定那里发生了什么,我怀疑你还没有告诉我们一切:)另一种方法可能是修改弹出函数以关闭窗口,而不是让窗口自行关闭。

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

这可能会更好一点,不确定。但从长远来看,我强烈建议避免弹出窗口并使用内联的东西。

Opening a popup window for an announcement like this could be problematic for people running popup blockers, which typically only allow popups to appear in response to a user-initiated event like clicking on something. A better approach would be to use an inline popup which would also give you the opportunity to display the popup modally (i.e. mask the rest of the page with a semi-transparent div) if you require them to acknowledge your message.

The use of self.close() should not close the original window/tab opened by the user, it should only close things that have been 'open'ed so I'm not sure what's going on there, I suspect you haven't told us everything :) An alternate approach might be to modify your popup function to close the window rather than have the window close itself.

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

This may work a little better, not sure. But in the long run, I highly recommend avoiding popups and using something inline instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文