Difference between [removed] and location.href

前端 未结 6 1420
一个人的身影
一个人的身影 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 08:14

    window.location is an object that holds all the information about the current document location (host, href, port, protocol etc.).

    location.href is shorthand for window.location.href (you call location from global object - window, so this is window.location.href), and this is only a string with the full URL of the current website.

    They act the same when you assign a URL to them - they will redirect to the page which you assign, but you can see differences between them when you open the browser console (firebug or developer tools) and write window.location and location.href.

提交回复
热议问题