[removed].href vs clicking on an Anchor

前端 未结 6 720
鱼传尺愫
鱼传尺愫 2020-12-03 07:17

What\'s the difference between clicking on:


vs.

calling window.location.href = ...

?

6条回答
  •  忘掉有多难
    2020-12-03 08:06

    Don't forget that in addition to the above answers, clicking on a hyperlink (anchor tag) will trigger that element's onclick handler (if any), whereas the Javascript version clearly doesn't and just changes the window's location.

    It is possible to manually invoke the onclick handler from Javascript if you want to simulate a click, but you must remember to do this manually. The snippets you posted would differ in this regard, which could be the cause of any behavioural differences.

提交回复
热议问题