js 处理浏览器显示地址

输入 www.test.com、www.test.com/home

显示 www.test.com/home/index

    <script>
    window.onload = function () {//浏览器地址处理
            if (window.location.pathname.toLowerCase().indexOf("home") == -1) {
                var pathname = window.location.pathname;
                pathname = pathname + '/home/index';
                pathname = pathname.replace("//", "/")
                window.open(window.location.origin + pathname, '_self');
            } else if (window.location.pathname.toLowerCase().indexOf("index") == -1) {
                var pathname = window.location.pathname;
                pathname = pathname + '/index';
                pathname = pathname.replace("//", "/")
                window.open(window.location.origin + pathname, '_self');
            }
        });
    </script>

 

posted @ 2019-08-29 10:54  怪先生  阅读(674)  评论(0编辑  收藏  举报