17

Using the TabMixPlus plugin for Firefox or Chrome, I can right click a page and choose "reload every..." and I could choose an interval.

I'd prefer not to install a plugin unless I really have to, and I am aware that you can type special things into Chrome's address bar.

This makes me think that something like this typed straight into the address might work:

javascript:setInterval(window.location.reload(), 2000); //2 secs`

I haven't managed it yet, but still don't want to rule it out as a possibility.

Is this possible?

6
  • Why are you against a plugin? If you are that worried just write your own plugin that does exactly what you want. – Ramhound Jun 13 '12 at 11:16
  • I'm not against plugins, sorry if it reads like that. I'd just like to learn a bit more about Chrome's address bar's capabilities :) – jon Jun 13 '12 at 11:31
  • Why haven't you tried typing this into the address bar? – Toby Allen Jun 13 '12 at 13:21
  • I have, see i haven't managed it yet – jon Jun 13 '12 at 13:22
  • 1
    The problem is that once you call location.reload() and the page reloads, as far as Chrome is concerned it's basically like loading a new page and the context is all new (the things you typed previously are lost). So you need to persist your code somehow and have the page be the same, which is why the iframe solution of the answer. – ShreevatsaR Mar 5 '16 at 18:05
20

After 6 years I have a solution for this!

The answer is inspired by the other answers here.

Edub's answer didn't work for me, it reloaded the page over and over, and didn't observe setInterval's duration parameter. I don't understand why Edub's answer doesn't work as expected.

This works for me in Chrome 67:

javascript:document.getElementsByTagName("body")[0].innerHTML = "<iframe id=\"testFrame\" src=\""+window.location.toString()+"\" style=\"position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;\"><\/iframe>";reloadTimer = setInterval(function(){ document.getElementById("testFrame").src=document.getElementById("testFrame").src },10000)

Formatted version:

document.getElementsByTagName("body")[0].innerHTML = 
"<iframe id=\"testFrame\" 
        src=\"" + window.location.toString() + "\" 
      style=\"position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;\">
<\/iframe>";
reloadTimer = setInterval(
    function(){ 
        document.getElementById("testFrame").src=document.getElementById("testFrame").src
    },
    10000
)

This works by replacing the current document body with an iframe pointing to the window's current location.

Then a call to setInterval is made, that makes the page reload on a timer.

This works well as a bookmark. setInterval's complementary function can be called by bookmark too: javascript:clearTimer(reloadTimer)

Notes:

  • Some sites detect they are being accessed via iframe and attempt to prevent access (Stack sites for instance!)

  • Browsers strip the prefix javascript: when pasting into the address bar so it has to be entered manually. However javascript: is not stripped if entered via bookmark.

1
  • Damn, it works a treat! Nice going! And good on you for solving your own problem. – Joshua Pinter Feb 17 at 15:29
11

You could do it through the Chrome Developer Tools using key combination ctrl+shift+j. Load the page you want, say for example: http://www.w3schools.com/jsref/dom_obj_frame.asp then hit ctrl+shift+j to open the developer tools. Right click on the body tag and select edit as html replace the inner contents (leaving the tag and closing tags intact) with the following:

<iframe id="testFrame" src="http://www.w3schools.com/jsref/dom_obj_frame.asp" style="position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;" onload="setInterval(document.getElementById('testFrame').contentWindow.location.reload(), 10000);"></iframe>

to stop editing as html you can either hit esc or click on one of the tags outside of the one you're editing. The page should start reloading every 10 seconds, you can close the developers tools if you'd like and it will continue to refresh, no plugin needed :)

1
  • Thanks Justin, this works so I have upvoted, but it's not the answer I was looking for so will leave the question open in hope :) Also, F12 non? – jon Jun 13 '12 at 18:54
3

Taking the solution from Justin Buser one step further lead me to:

document.getElementsByTagName("body")[0].innerHTML = "<iframe id=\"testFrame\" src=\""+window.location.toString()+"\" style=\"position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;\" onload=\"setInterval(document.getElementById(\'testFrame\').contentWindow.location.reload(), 10000);\"><\/iframe>"

The idea to embed the site in an iframe to be able to reload it works fine (i guess). I just wrote some code to get the body elment and replace the innerhtml with an Iframe to the current url.

This way it is possible to bookmark some JavaScript code and fire it at any site to reload it. Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.