When I open some web pages, they may jump to another web page automatically after a while. For example, if you open https://list.jd.com/list.html?cat=670,677,688 it will jump to cfe.m.jd.com/..., then further jump to passport.jd.com that asks you to login. I think on the page list.jd.com/..., there must be a statement like window.location.href=...that causes the jump. But where is the statement? How can I find the statement in a systematic way? I mean I can press F12 and set a breakpoint on that statement then refresh the page to stop at that statement.
How to locate the js statement that jumps to another web page?
171 Views Asked by William At
2
Not all redirects are done using JavaScript so that means there won't always be a
location.hrefto look for in a script. In fact it's quite the opposite. Most redirects like the one you gave in your example are done on the server, load balancer or most likely by the DNS provider, more explanation here.If you
curlthe url in your example you will see there is a302:You can tell
curlto follow this redirect with the-Loption:There a couple of scipts listed in that response so you could see what is happening in those scripts.
The best way would be to go into your dev tools (for illustration I'll use Chrome) and select:
Sourcestab.Event Listener BreakpointsLoadLoadandUnload.Paste
https://list.jd.com/list.html?cat=670,677,688and see the various stages of theLoadandUnload. The browser will pause at these breakpoints. Good luck with your exploration.