[removed] Setting location.href versus location

后端 未结 7 1788
野性不改
野性不改 2020-11-22 17:16

When would you set location to a URL string versus setting location.href?

location = \"http://www.stackoverflow.com\";
7条回答
  •  囚心锁ツ
    2020-11-22 17:46

    With TypeScript use window.location.href as window.location is technically an object containing:

    Properties
    hash 
    host 
    hostname
    href    <--- you need this
    pathname (relative to the host)
    port 
    protocol 
    search 
    

    Setting window.location will produce a type error, while window.location.href is of type string.

    Source

提交回复
热议问题