First, you want to show counter
on the screen, not timer
. Second, you need to update the message every time your counter changes:
var timer = setInterval(function () {
counter--;
$('#msg').html('Page will refresh in ' + counter);
if (counter == 0) {
clearInterval(interval);
}
}, 1000);