window.loaction.href和window.loaction.hash的区别

                 综:    

window.location.href表示重定向,后面跟着的是完整的url地址,与其相似的还有window.location.hash,下面来比较window.location.href和window.locaiton.hash的区别。

       (1)window.location.href

                得到和使用的是完整的url,比如window.location.href="www.baidu.com”表示的是重新定向,页面跳转到新的页面。也可以通过window.location.href得到a标签的完整的href,比如<a href="#book">如果使用href,那么可以得到完整的链接(url)

       (2)window.location.hash

              得到的是锚链接。相比如href,通过window.location.hash并不会跳转到新的链接,只会在当前链接里面改变锚链。并且如果有<a href="#book">通过window.location.hash得不到完整的链接(URL),仅仅得到#book.

猜你喜欢

转载自blog.csdn.net/m0_60237095/article/details/127139274