Home  >  Q&A  >  body text

javascript - When using location.href to jump to a page, it does not jump immediately?

location.href="login.html"

I found that it does not jump immediately after executing this statement, but after all the JS statements following the statement are executed, the jump is performed. Why?

怪我咯怪我咯2644 days ago969

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-06-28 09:30:41

    The assignment of

    window.location.href will not interrupt the execution of Javascript. So it’s best to add a statement like return at the end to end it

    reply
    0
  • ringa_lee

    ringa_lee2017-06-28 09:30:41

    If you need to jump directly without executing the following, you can add return false;

    after the jump

    reply
    0
  • PHP中文网

    PHP中文网2017-06-28 09:30:41

    No, I tested it and it didn’t happen. It jumps immediately. You can post your code and see if it has anything to do with your code, such as whether it is in an asynchronous function

    reply
    0
  • Cancelreply