,所以我使用Countdown.js插件来显示下一个呼叫时间表。
我想在5分钟前,2分钟前和末日前1秒制作poup。
目前,我可以在结束时间之前仅显示弹出窗口,我的代码如下。
<script type="text/javascript">
$(function () {
var austDay = new Date(<?php echo strtotime(Date::Add($next_scheduled_call->next_call_time))*1000; ?>);
$('#defaultCountdown').countdown({until: austDay,onExpiry: callDue});
});
function callDue(){
@if($isSalesManagerGroup == 'no')
alert('Your Call is Get to Due , Please Update Soon.');
location.href= "{{ URL::to('/home/leads/history/'.$next_scheduled_call->leads_id.'')}}";
@endif
}
</script>
如何修改此代码以获取上述要求
具有一些Date
功能,借助setTimeout
,您可以如下实现:
<script type="text/javascript">
$(function () {
var austDay = new Date(<?php echo strtotime(Date::Add($next_scheduled_call->next_call_time))*1000; ?>);
var currentDate = new Date(); //current Date
var diff_in_sec = (austDay.getTime() - currentDate.getTime())/ 1000;
var Seconds_Between_Dates = Math.ceil(diff_in_sec);
var timeBefore5Min = Seconds_Between_Dates - (5 * 60);
var timeBefore2Min = Seconds_Between_Dates - (2 * 60);
$('#defaultCountdown').countdown({until: austDay,onExpiry: callDue});
setTimeout(function(){
callDue(); //calling function before 5 min
},timeBefore5Min * 1000);
setTimeout(function(){
callDue(); //calling function before 2 min
},timeBefore2Min * 1000);
});
function callDue(){
@if($isSalesManagerGroup == 'no')
alert('Your Call is Get to Due , Please Update Soon.');
location.href= "{{ URL::to('/home/leads/history/'.$next_scheduled_call->leads_id.'')}}";
@endif
}
</script>