2

How can I save the foo variable (in this case a function) after the page gets reloaded? How can I call foo after the page was reloaded automatically?

var foo = function() {
  if(bar){
    location.reload();
    console.log('reload');
  }else{
    console.log('do something');
    //do something
  }
};
foo();

2 Answers 2

1

I found a solution by myself using the chrome extension Resource Override. https://chrome.google.com/webstore/detail/resource-override/pkoacgokdfckfpndoffpifphamojphii

Just added the foo function to the head of the site and the function call to the body. Every time the side reloads, the code will be written inside the site (locally).

Sign up to request clarification or add additional context in comments.

Comments

-1

You can't save the stuff that is evaluated in a console. Meaning everything that is evaluated in a console lives only during current page session. Once the page is reloaded - all the evaluation results are erased. In case if you still need to store this function - you might use localStorage or sessionStorage. But it is really redundant to store the function such a way... Why don't include this function directly to the html and be able to call it any time after the page is reloaded?

2 Comments

Because I want to check a website for an update. I can't include to the script to the website. Is it possible to store the function in localStorage?
Yep, it is possible even though it is not recommended. It is well described here stackoverflow.com/questions/38926530/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.