js中获取当前url路径

js获取url

                let url = window.location.href;
                console.log(url)

                // 返回当前页面的路径和文件名,如:/testdemo/test.html
                let pathname = window.location.pathname;
                console.log(pathname)

                // 返回 web 主机的端口,如:8080
                let port = window.location.port;
                console.log(port)

                // 返回所使用的 web 协议,如:http:
                let protocol = window.location.protocol;
                console.log(protocol)

                // 获取参数,如:?id=1&name=test
                let search = window.location.search;
                console.log(search)

                // 获取带参数的url       //  /manage/table/Village?uygu=321
                console.log(pathname+search);        

 刷新当前页面

location.reload()
原文地址:https://www.cnblogs.com/shizhengwen/p/14215699.html