Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 720 Bytes

JavaScript.md

File metadata and controls

37 lines (27 loc) · 720 Bytes

JavaScript

Auto refresh image

window.onload = function() {
    const image = document.getElementById("img");

    function updateImage() {
        image.src = image.src.split("?")[0] + "?" + new Date().getTime();
    }

    setInterval(updateImage, 1000);
}
<img src="<image.jpg>" id="img" />

Detect mobile browser

const isMobileDevice = /Mobi/i.test(window.navigator.userAgent);

Redirect to HTTPS

if (!/https/.test(window.location.protocol)) {
    window.location.href = window.location.href.replace("http:", "https:");
}