Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug which Javascript is causing a redirect

Tags:

javascript

We have mountains of Javascript. Somewhere in there, a redirect is happening that we don't want. How can you generically debug which code caused a redirect? A stack trace would be perfect.

like image 249
Dave Aaron Smith Avatar asked Apr 18 '12 16:04

Dave Aaron Smith


People also ask

How do I stop JavaScript redirects?

In that case, the new page can use JavaScript to redirect our article to a phishing page asking for BleepingComputer credentials. To prevent this from happening, a rel="noopener" HTML link attribute was created that prevents a new tab from using JavaScript to redirect the page.

What is JavaScript 301 redirect?

“If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.”

Can JavaScript redirect?

JavaScript has the APIs that allow you to redirect to a new URL or page. However, JavaScript redirection runs entirely on the client side. Therefore it doesn't return the status code 301 (move permanently) like a server redirection.


2 Answers

There's no easy way. You could do a mass search in your files for some words like "redirect", "window.location", "location" and the like.

like image 125
Alex Turpin Avatar answered Sep 28 '22 08:09

Alex Turpin


Another person asked a similar question. Someone gave a helpful option in chrome debugging tools that you could try out. See link below.

Break javascript before an inline javascript redirect in Chrome

like image 38
Daniel Avatar answered Sep 28 '22 06:09

Daniel