[removed] Setting location.href versus location

后端 未结 7 1709
野性不改
野性不改 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 18:03

    Like as has been said already, location is an object. But that person suggested using either. But, you will do better to use the .href version.

    Objects have default properties which, if nothing else is specified, they are assumed. In the case of the location object, it has a property called .href. And by not specifying ANY property during the assignment, it will assume "href" by default.

    This is all well and fine until a later object model version changes and there either is no longer a default property, or the default property is changed. Then your program breaks unexpectedly.

    If you mean href, you should specify href.

    0 讨论(0)
提交回复
热议问题