-1

I have a requirement which needs to load after reloading the page with Jquery. Below is the code.

$("a[id='gobutton']").click(function(e)) { 
  location.reload();
  somefunc(); 
});
function somefunc() { 
  alert("run my script"); }
  • Does this answer your question? [Refresh page and run function after JavaScript](https://stackoverflow.com/questions/41904975/refresh-page-and-run-function-after-javascript) – Reyno Oct 13 '21 at 14:12

1 Answers1

0

After you run location.reload() your code is gone. You cant run anything after it. You would need to pass an argument to the page to run the function.

let param = new URLSearchParams(location.search);
$("a[id='gobutton']").click(function(e)) { 
  location.href = '?somefunc=true' 
});

if(param.get('somefunc'){
  somefunc()
}
function somefunc(){}

DropMania
  • 123
  • 1
  • 11