Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Javascript Countdown

Featured Replies

A client has asked me to look into a shipping countdown script, the idea is that a countdown will be shown on the site stating if the customer orders within a set time their item will be shipped same day. I've managed to find a script which does this and altered it slightly. However, they need this to account for timezones, ideally it needs to work of the server time or some online clock since user clocks are often wrong. Another thing it needs to account for is weekends, ie on a saturday the order time would be much shorter and a sunday wouldnt have delivery at all so it would shift to monday.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
 <title></title>
<script type="text/javascript">
/*<![CDATA[*/
function Shipping(id){
var today=new Date();
var hours=today.getHours();
var day=today.getDay();
document.getElementById(id).innerHTML=(hours<16)?'orders completed in the next '+(16-hours)+' hour ship today':'orders completed in the next 18 hours ship during the next business day';
}

/*]]>*/
</script></head>

<body>

<span id="tst" ></span>
<script type="text/javascript">
/*<![CDATA[*/
Shipping('tst');
/*]]>*/
</script>
</body>

</html>

 

My main problem is i dont completely understand the above, i can see how its pulling the time but my javascript knowledge is pretty much non existent so im really struggling. If someone could just help me understand how i could add the equivalent of an if statement or & i could probably figure most of this out with the exception of the timezone / server time.

 

e.g. i figure to account for weekends id need something like:

document.getElementById(id).innerHTML=(day=saturday)?'orders completed in the next '+(10-hours)+' hour ship today':'orders completed in the next 48 hours ship on Monday';

 

Any help would be really appreciated.

 

Thanks

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.