Edit in JSFiddle

window.onload = function()
{
    if("performance" in window)
    {
        if("navigation" in window.performance)
        {
            document.getElementById("result").innerHTML = "Page Performance API supported";
            
            var type = window.performance.navigation.type;
            
            if(type == 0)
            {
                document.getElementById("page_visit_type").innerHTML = "User typed URL or clicked a link or submitted a form or script redirect";
            }
            else if(type == 1)
            {
                document.getElementById("page_visit_type").innerHTML = "User refreshed the page";
            }
            else if(type == 2)
            {
                document.getElementById("page_visit_type").innerHTML = "User navigated to this page using back or forward button";
            }
            else if(type == 255)
            {
                document.getElementById("page_visit_type").innerHTML = "Don't know how user landed on this page.";
            }
            
            document.getElementById("redirections_occured").innerHTML = "Number of redirections occured to land on this page is: " + performance.navigation.redirectCount;
        }
        else
        {
             document.getElementById("result").innerHTML = "Page Navigation API not supported";
        }
    }
    else
    {
        document.getElementById("result").innerHTML = "Page Performance API not supported";
    }
}
<div id="result"></div>
<div id="page_visit_type"></div>
<div id="redirections_occured"></div>