title: get newURL from a redirect event in JavaScript
body: <p>I am using a template blogger with an 'ad virus'.</p>
  
  <p>The virus redirect users to others pages like bet365.com.</p>
  
  <p>The virus is scrambled and I can not think of a quick way to unscramble.</p>
  
  <p>As I can not find the 'href' for 'ad links' in 'dom' or 'http links' for 'windows.location.href' in the javascript code since it is scrambled.</p>
  
  <p>I thought about getting the final output link using some listener for redirect event JavaScript like OnHashChange and then cancel the redirect if it was an 'ad link'.</p>
  
  <p><a href="https://developer.mozilla.org/pt-BR/docs/Web/API/WindowEventHandlers/onhashchange" rel="nofollow noreferrer">https://developer.mozilla.org/pt-BR/docs/Web/API/WindowEventHandlers/onhashchange</a></p>
  
  <p>Where OnHashCahnge return the new URL and old URL, but only for hash urls.</p>
  
  <p>So I try beforeunload</p>
  
  <p><a href="https://developer.mozilla.org/pt-BR/docs/Web/Events/beforeunload" rel="nofollow noreferrer">https://developer.mozilla.org/pt-BR/docs/Web/Events/beforeunload</a></p>
  
  <p>But although I can use a function before leaving the page, it does not return the new URL</p>