Use setTimeout() method. Try this
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
time=3000;//time to stay on, in milliseconds
function closeMes(){
document.getElementById('mes').style.display='none'
}
window.onload=function(){setTimeout('closeMes()',time)}
</script>
</head>
<body>
<div id="mes" style="position:absolute; background-color:#CCCCCC">This message will stay on for 3 seconds</div>
</body>
</html>