Hiển thị thời gian tải trang cho blog/website

Thêm công cụ hiển thị thoải gian tải trang cho blog/website như demo bên dưới
Đang tính thời gian tải trang...

HTML

Dán đoạn code bên dưới vào nơi muốn hiển thị thời gian tải trang
<div id="load-time">Đang tính thời gian tải trang...</div>

Script

<script>
var showTime = document.getElementById('load-time'),
    startTime = (new Date()).getTime(); // Get the time before `window.onload`

window.onload = function() {
    // Get the current time in `window.onload`
    var endTime = (new Date()).getTime();
    // Now use the `startTime` and `endTime` to calculate the seconds
    // And show the result inside `#load-time`
    showTime.innerHTML = "Thời gian tải trang: " + ((endTime-startTime)/1000) + " giây(s).";
};
</script>

About the author

Đỗ Thu Hoài
Ko biết để gì cho hợp lý! https://www.threads.com/@dwo_th

Đăng nhận xét