Company News

Adding an Auto-Refresh Content Editor Web Part

May 16, 2011

The Challenge

You want to create a dashboard which will automatically refresh itself on a regular basis

The Solution

This is easily accomplishable using a SharePoint Web Part and little bit of scripting, JavaScript in this case, to be precise.

How to Accomplish This Task

Start by going to the page you want to edit, and begin editing the page (you will obviously have to have rights to do this).

Add a Web Part to your page (you should already be in a mode like below).

Choose the “Media and Content” Category, “Content Editor” Web Part, and add it to any part of the page (such as the “Header”).

Select the web part and choose “Edit Web Part” from the drop down. A menu will appear on the top right hand side of the page, you may need to scroll over/up to find it.

Set the Title to “Refresh the Web Page”.

Set the Chrome Type to “None”.

Click OK to accept those changes. Then you need to add the script to the web page. To do this, you start by clicking in the section “Click here to add new content”.

A cursor will appear in the content area, however, don’t type anything in the content area, instead simply go to the ribbon and under Editing Tools -> Format Text, select the HTML drop down, and choose “Edit HTML Source”.

In the HTML Source box, enter the following JavaScript code.

function refreshPage()
   window.location = window.location;
setTimeout(refreshPage, 300000);

Basically, this script is calling a function after 5 minutes (1000 milliseconds * 60 seconds * 5 minutes = 300000 – this can be any value you choose, just do the math right), which will refresh the page (without showing the annoying, “Are you sure you want to resubmit this page” message that appears in IE when using “window.location.reload”).

Finally, stop editing the page and you will be all done.

Your page should now have a hidden Web Part which will refresh the page every 5 minutes (or whatever number you should choose).


20 Responses

  1. CStone says:

    It doesn’t work for all applications, but the Ajax refresh availabe on web-parts is also a great way make sure the information is up to date.

    Doesn’t require any code and only refreshes the specific web-part data instead of doing a full page refresh so it’s easier on the server.

  2. Mary says:

    but not every web part has an Ajax refresh, right? or is this something we can turn on/off

  3. MMMan says:

    No, the ajax refresh on web parts isn’t available universally, plus it will only update the particular web part, not an entire page. The idea for this post was to provide a means to force a page refresh, not a web part refresh.

  4. GGGman says:

    I messed up and put a typo in the script for the refresh rate. Meant to put 15000 but I put 1500. Now the page refreshes so fast that I can’t get to where I can re edit the web part to fix that. Is there another way to edit a web part or do I have to rebuild the page? Thanks for the help.

  5. Hi,

    Thanks for your help,it really helpful for me.

  6. B Baker says:

    How do you remove embedded code from sharepoint 2013?

  7. Jeremy says:

    Great post – worked like a dream!

  8. SeaCooper says:

    Thanks for taking the time to write this post, worked like a charm!

  9. Arvin says:

    Can this be done in Sharepoint online?

  10. eric says:

    Thanks for your help but my sharepoint says warning your html source may have been modified then justs the code as normal text on the page.

  11. Rob says:

    eric, the message “Warning: the html source you entered might have been modified” is quite normal and you can safely ignore it. It’s just telling you that you have changed the html source of the page.

    Colin missed out one slightly important part in that the javascript needs to be wrapped in . The full code you enter is as follows:

    function refreshPage()
    window.location = window.location;
    setTimeout(refreshPage, 300000);

  12. Rob says:

    Apologies, the relevant code got stripped out of my previous post.

    The code you need is:

    “” (remove the first and last “)
    then add the javascript above, then
    “” (remove the first and last “)

  13. Rob says:

    Streuth, it’s still getting stripped out. You can see the code on the page on my site at

  14. jay says:

    We’ve been monitoring a server and can see a page that has a lot of autorefresh webparts on it. what sort of memory hit can this add to the server?

  15. Klaus says:

    Thanks for the post, this is what I was looking for. However, I found two issues with the solution:

    1. With the webpart added to the top of the list, users now can’t select different views anymore. The view dropdown disappears, but returns as soon as the webpart is deleted.

    2. When auto-refreshing, I get a “The webpage cannot be found” error, and the URL of the list is changed to http://sitename/Lists/listname/object%20Location, i.e. has [object%20Location] appended to the list address.

  16. Skyggles Merina says:

    Thank you for the link with code.
    Worked like a charm.

Leave a Reply

Colin Phillips

Colin Phillips

Subscribe via Email


Powered by...

itgroove Corporate Profile
Connect With Us