location.href
href屬性說明
href是location最重要的屬性,用於獲取當前文檔的URL或設置URL。如果設置URL,將導航到新的頁面,例如:
location.href="http://www.xxx.com/";
將導航到xxx首頁。
使用這種方式導航,新頁面的地址將被加入history的地址列表中,因此可以使用back或go函數導航。assign函數在設置URL時與location.href具有完全相同的功能。
可以使用replace函數,它將新頁面的地址在history的地址列表中刪除,因此使用back或go函數無法導航。
location.href : http://xxx.com:80/test/index.php?u=123#top
location.protocol : http
location.hostname : xxx.com
location.host : xxx.com:80
location.port : 80
location.pathname : /test/index.php
location.search : ?u=123
location.hash : #top
沒有留言:
張貼留言