简体   繁体   中英

Javascript - How to get the new window Referrer after Redirection

I am trying to solve an issue that although seems to have been answered several times, not any of the solutions work for me. The scenario is when user presses a button to redirect him to another page (of the same domain) and then when few actions have completed to be redirected to the initial again. So, at first place, I need to get the new referrer of the page that the user is redirected. I've tried solutions with new referrer or without referrer such as the following ones with no luck:

function a() {
  var ref = window.open("http://localhost:8080/ui/about"); 
  ref.addEventListener('loadstart',function(iABObject){
  alert("print something");
  ToDo(); 
}                               

or second solution

function a() {
  window.location.href = "http://localhost:8080/ui/about";
  if(window.location.href.indexOf("localhost:8080/ui/about")>-1 ){ 
     alert("print something");
     ToDo();
  }
}

Any kind of help is appreciated.

I think you want to do something like this: pageA:

function onClickMyButton(){
    window.location = "pageB";
}

pageB:

... do some stuff
window.location = document.referrer;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM