前端獲取當前路徑
- //獲取當前窗口的Url
- //returnUrl=http://localhost:8080/shopping/buyCart.shtml?skuId=510&amount=1
- window.location.href
- //獲取當前窗口的主機名 例如:http://localhost:8080
- window.location.host
- //獲取當前窗口的端口 例如: 8080
- window.location.port
- //獲取當前窗口的路徑 例如: /shopping/buyCart.shtml
- window.location.pathname
- //獲取當前文檔的Url
- document.URL
- //獲取參數 例如: ?skuId=510&amount=1
- window.location.search
- //跳出當前窗口,打開新窗口
- window.open(url);
- document默示的是一個文檔對象,window默示的是一個窗口對象,一個窗口下能夠有多個文檔對象。
因此一個窗口下只有一個window.location.href,然則可能有多個document.URL、document.location.href
- window.location.href和document.location.href能夠被賦值,而後跳轉到其它頁面,document.URL只能讀不克不及寫
歡迎關注本站公眾號,獲取更多信息