Skip to content

Instantly share code, notes, and snippets.

@dozer111
Last active October 8, 2019 11:56
Show Gist options
  • Save dozer111/004d1073da4d5d7bc2579436b1836a33 to your computer and use it in GitHub Desktop.
Save dozer111/004d1073da4d5d7bc2579436b1836a33 to your computer and use it in GitHub Desktop.
Force redirect on js
function url_redirect(url){
    var X = setTimeout(function(){
        window.location.replace(url);
        return true;
    },300);

    if( window.location = url ){
        clearTimeout(X);
        return true;
    } else {
        if( window.location.href = url ){
            clearTimeout(X);
            return true;
        }else{
            clearTimeout(X);
            window.location.replace(url);
            return true;
        }
    }
    return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment