Difference between [removed] and location.href

前端 未结 6 1418
一个人的身影
一个人的身影 2020-12-01 07:35

I am confused as to the difference between window.location and location.href. Both appear to be acting in the same way.

What is the differe

6条回答
  •  误落风尘
    2020-12-01 07:50

    Check this old MDN article:

    Location objects have a toString method returning the current URL. You can also assign a string to window.location. This means that you can work with window.location as if it were a string in most cases. Sometimes, for example when you need to call a String method on it, you have to explicitly call toString:

    window is just the global object that houses several properties, one of them is location. location also has properties, one of them is href. location.href is just window.location.href

提交回复
热议问题