2014-09-29 45 views
0

我看了一下,並嘗試使用我在網上找到的腳本來設置一個預定的彩盒,到目前爲止它只能在Chrome中工作。以下是我目前正在使用的腳本。我知道這一定是非常基本的,但我希望有人能幫助或指出正確的方向。按時間表彈出的彩盒

UPDATE

我想什麼是有顏色框顯示,每次當人們訪問時,顏色框將禁用它的功能時,它通過「ScheduleDate」,現在只有鑲邊將顯示顏色框按計劃進行,即Firefox和Safari瀏覽器似乎無法識別腳本。瀏覽器控制檯中沒有錯誤。

<script> 
    today = new Date(); 
    today_year = today.getFullYear(); 
    today_month = today.getMonth()+1; 
    today_date = today.getDate(); 
    today_hours = today.getHours(); 
    today_minutes = today.getMinutes(); 
    today_seconds = today.getSeconds(); 

    var CurrentDate = today_year+"-"+today_month+"-"+today_date+" "+today_hours+":"+today_minutes+":"+today_seconds; 
    var ScheduleDate = "2014-10-12 00:00:00"; 

    if ( (Date.parse(CurrentDate)).valueOf() <= (Date.parse(ScheduleDate)).valueOf()) 
    { 
     $(document).ready(function(){    
      $(".iframe").colorbox({iframe:true, width:"300px", height:"250px", open:true});    
     });      
    } 
</script> 
+0

那麼,有什麼問題? SO不是代碼評論網站。順便說一句,你可以將'$(document).ready()'移動到腳本的開頭。 – 2014-09-29 04:13:38

+0

正如我所說,它只適用於鉻。所以我發佈代碼是因爲我認爲其他人更容易理解我的問題,我不知道編碼,將它們結合起來是我能做的最好的。我認爲一定是做錯了事,但我無法弄清楚。 – Fatboonbo 2014-09-29 05:40:50

+0

像什麼不在其他瀏覽器中工作?您嘗試了其他瀏覽器?瀏覽器控制檯中是否有任何錯誤消息? – 2014-09-29 05:43:21

回答

0

有,我需要做的就是你的代碼在Firefox中工作兩件事情:

  1. 包裝所有您的JavaScript的$(document).ready()內碼。
  2. 更改您的CurrentDate的構建和比較方式。

運行下面的堆棧片段或參考此jsfiddle。另外,我從他們的examples之一拿了CSS。

// javascript 
 
$(document).ready(function() { 
 
    var currentDate = new Date(); 
 
    var scheduleDate = new Date(2014, 9, 12, 0, 0, 0); 
 

 
    if (currentDate <= scheduleDate) { 
 
    $.colorbox({ 
 
     iframe: true, 
 
     innerWidth: "300px", 
 
     innerHeight: "300px", 
 
     open: true 
 
    }); 
 
    } 
 
});
<!-- HTML --> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="http://cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.4.33/example1/colorbox.css" rel="stylesheet"/> 
 
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.4.33/jquery.colorbox-min.js"></script>