7

I am trying to run some javascript in google chrome console. In it somewhere between I need to perform

location.reload();

So that page gets refreshed, but with it whole console data (functions which I am defining in colsole) gets destroyed. So my question is as follow: Is there any way to refresh a webpage without reloading console window?

vishtree
  • 379
  • 1
  • 3
  • 13
  • Wrong approach. You want to persist the state of your console. When page is realoaded, console is reinitialised too. But, there's `presist` option in FF and Chrome console which will do what you need. However, any functions defined in console will not be preserved only the output that is currently in the console. – marekful Jan 25 '13 at 18:04
  • 1
    then is there any way to define function permanently in console so that I can use it even after refreshing? – vishtree Jan 25 '13 at 18:07
  • I don't think so, but you can define those functions in the page you load from the server so they will be present after each reload. – marekful Jan 25 '13 at 18:08
  • Another approach is using AJAX. Don't do a full page load, only load your page using AJAX inside a 'container' div (which may even be your full page). – marekful Jan 25 '13 at 18:09
  • Possible duplicate of [How to get JS variable to retain value after page refresh?](http://stackoverflow.com/questions/16206322/how-to-get-js-variable-to-retain-value-after-page-refresh) – KyleMit May 02 '17 at 14:33

3 Answers3

11

No. The console is a property of the window object, which is what you're reloading.

You can overrule that at the browser level by keeping the console log data on reload, but it won't be part of the new window's scope: Chrome: Developer Tools > Console > Preserve log upon navigation

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
2

In chrome developer tool, right click console->preserve log upon navigation would persists the chrome console even when you refresh the page.

Vimalnath
  • 6,373
  • 2
  • 26
  • 47
0

Chrome consolve section click on the setting icon and open the one pop-up, check the preserve log option. After show all the console page.

enter image description here

Cristik
  • 30,989
  • 25
  • 91
  • 127