How to execute some jQuery or JavaScript code after a redirect has completed
javascript, jquery, redirect
Solution
It is impossible to tell JavaScript to execute some code after a redirect.
However you have different options:
- Pass a string in the redirect URL and then do something on "ready"
- Store some information in a cookie and then do something on "ready"
- Store some data using DOM storage (namely `sessionStorage`) if you don't mind the smaller browser support
Problem
How can I execute jQuery/JS code as soon as a jQuery/JS redirect like... ``` $(location).attr('href','/target_path'); ``` ...or... ``` window.location.href = "/target_path"; ``` ...has finished loading the new page? Specifically, I need to pass an alert message and insert it into and display it (enclosed in some HTML) on the new page.