Code tự động tải lại (auto refresh) trang web, blogger
Tự động tải lại trang hay auto refresh là một thủ thuật để tăng view cho website. Với lượng truy cập trung bình hàng ngày rất thấp vì thế để tạo nên lượng traffic lớn không thể không nhắc tới auto refresh. Có vài cách làm nhưng trong bài viết này mình chia sẻ một đoạn code sử dụng javascript
Code tự động tải lại (auto refresh) trang web, blogger
<script language="JavaScript">
var countDownInterval=30; //1 refresh page
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200
</script>
<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
<script>
var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.reload()
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){
document.c_reload.document.c_reload2.document.write('Website s? t? d?ng <a href="javascript:window.location.reload()">refresh</a> trong <b id="countDownText">'+countDownTime+' </b> giây')
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}
function startit(){
if (document.all||document.getElementById)
document.write(' <a href="javascript:window.location.reload()">refresh</a> trong <b id="countDownText">'+countDownTime+' </b> 1')
countDown()
}
if (document.all||document.getElementById)
startit()
else
window.onload=startit
</script>
Code tự động tải lại (auto refresh) trang web, blogger
Tùy chỉnh:- var countDownInterval=30; là thời gian auto refresh lại trang ban có thể thay thế nó
Các bạn có thể xem thêm: Tự động chuyển trang (Auto Redirect) cho website, blog