How to execute some jQuery or JavaScript code after a redirect has completed

后端 未结 4 1625
心在旅途
心在旅途 2021-01-20 00:21

How can I execute jQuery/JS code as soon as a jQuery/JS redirect like...

$(location).attr(\'href\',\'/target_path\');

...or...



        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 01:16

    It is impossible to tell JavaScript to execute some code after a redirect.

    However you have different options:

    1. Pass a string in the redirect URL and then do something on "ready"
    2. Store some information in a cookie and then do something on "ready"
    3. Store some data using DOM storage (namely sessionStorage) if you don't mind the smaller browser support

提交回复
热议问题