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

后端 未结 4 1624
心在旅途
心在旅途 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:00

    You can't. Once the redirect happens you are no longer on that page. You can't execute code on a page you are no longer on. If you want the next page to do something then you need to pass, either by cookie or URL parameter, a flag that instructs it to do so.

提交回复
热议问题