Creating a Count Down Timer when Customer Logs Out From Account in Magento

Magento has a very Lame Layout Screen when customer logs out. To make it little interesting I thought why not add a count down timer over there. So this is how i made a count down timer using JavaScript.

Goto : frontend/default/YOURTHEME/template/customer/logout.phtml

Now Create a span where in between which you want to display a timer.

<span id=”timer”>5</span>

After that add following Javascript code in the file :

<script type=”text/javascript”>
//<![CDATA[
window.onload = CreateTimer(“timer”, 5);
var Timer;
var TotalSeconds;

function CreateTimer(TimerID, Time) {
Timer = document.getElementById(TimerID);
TotalSeconds = Time;

UpdateTimer();
window.setTimeout(“Tick()”, 1000);
}

function Tick() {
TotalSeconds -= 1;
UpdateTimer();
if(TotalSeconds == 0){
location.href = ‘<?php echo $this->getUrl() ?>’
return 0;
}
window.setTimeout(“Tick()”, 1000);
}

function UpdateTimer() {
Timer.innerHTML = TotalSeconds;
}
//]]>
</script>

Please Note : Comment out the default redirection code ie: setTimeout(function(){ location.href = ‘<?php echo $this->getUrl() ?>’},5000)

This is it. Now enjoy your timer when cutomer logs out. I haven’t explained the code in detail as it is pretty simple. If you face any problem in it please post it as a comment.

Advertisements

3 thoughts on “Creating a Count Down Timer when Customer Logs Out From Account in Magento

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s