Web Site in sidebar Gadget; Need to Refresh Every 10 Seconds

I need to be able to display a web site in a sidebar gadget, and have it update every 10 seconds. It is used to monitor servers. The gadget needs to be about 500 x 600 pixels.

I have seen some messages talking about using iframes to display a web site in a sidebar gadget, but I cannot find a way to successfully get it to refresh at a specified interval (say every 10 seconds).

Any assistance and/or code samples would be greatly appreciated.

Thanks!



Answer this question

Web Site in sidebar Gadget; Need to Refresh Every 10 Seconds

  • RFDID

    Having a similar problem using AJAX, here's how I solved it...

    var http = getHTTPObject();

    function getHTTPObject() {
    var req;

    if(window.XMLHttpRequest) {
    try { req = new XMLHttpRequest(); } catch(e) { req = false; }
    } else if(window.ActiveXObject) {
    try { req = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {
    try { req = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { req = false; }
    }
    }
    return req;
    }

    http.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');

    Sorry if the posting is "sloppy"... this is my very first post here.. :p The last line of code is the "trick" here... just be sure it is set to a date in the past...



  • LadyReader

    I tried this and it does the refresh, but it still just pulls from the IE cache. If I manually clear the IE cache it loads the new page directly from the web site once, and starts pulling a stale page from the cache again. Any other ideas on how to get around this Thanks for your help!
  • smudie

    Much appreciated. Looks like it is trying to refresh now...but appears to be loading from the IE cache and so the content is not being updated. Is there a way to force it to go to the site and not the cache

  • JV Chevy

    I've tried to use this method to refresh the gadget but all of the content disappears and comes back a moment later and none of my links will work.

    Here is the whole script for the main gadget (It's an RSS gadget which I would like to update every 10 minutes), any help would be fantastic :

    Code Snippet

    <html>
    <head>
    <title>The Vista Forums Post Gadget</title>
    <link href="css/gadget_layout.css" rel="stylesheet" type="text/css" />
    <script LANGUAGE="JScript" >
    var theme ="TheVistaForums";
    var oXml = new XMLHttpRequest(); //ActiveXObject("Microsoft.XMLHTTP") //
    var responseData;
    var rssCount =0;
    var rssPage =0;
    var rsstimeout=3600;
    window.setInterval(refreshGadget, 10000);
    function refreshGadget() {
    location.href = location.href;
    }

    window.onload = function(){
    LoadThemeSettings();
    gRSS.innerHTML = "<img src=themes/"+theme+"/16-on-black.gif> Reading Posts...";

    System.Gadget.settingsUI = "Theme.html";
    System.Gadget.onSettingsClosed = SettingsClosed;
    PaintScreen();
    var oLoad = setTimeout(oLoado, 500);
    }

    function oLoado(){
    if (oXml ==null)
    oXml = new XMLHttpRequest();
    oXml.open( "GET", "http://thevistaforums.com/index.php act=rssout&id=3", true );
    oXml.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    oXml.send();
    }
    oXml.onreadystatechange = function(){
    if (oXml.readyState == 4)
    if (oXml.status == 200){
    var rXML = oXml.responseXML;
    responseData = rXML;
    gRSS.innerHTML ="";
    rssPage = 0;
    buildPage(0);
    oXml = null;
    var o = setTimeout(oLoado, rsstimeout);

    }
    }
    function SettingsClosed() {
    LoadThemeSettings();
    PaintScreen();
    }

    function LoadThemeSettings(){
    //Theme Code
    //-----------------------------------------------------------------------
    var gThemeSetting = System.Gadget.Settings.read("gThemeSetting");
    if (gThemeSetting != "")
    theme = gThemeSetting ;

    //background
    background.src = "Themes/"+ theme +"/Docked.png";
    //-----------------------------------------------------------------------
    }
    function PaintScreen(){

    System.Gadget.beginTransition();

    var NewPostsImage = background.addImageObject("Themes/"+ theme +"/NewPosts.png", 14, 167);
    var UsersOnlineImage = background.addImageObject("Themes/"+ theme +"/wiki.png", 14, 184);
    var ControlPanelImage = background.addImageObject("Themes/"+ theme +"/ControlPanel.png", 14, 200);
    var gnavBackImage = background.addImageObject("Themes/"+ theme +"/gnavBack.png", 40, 145);

    var buttonUp_OffImage = background.addImageObject("Themes/"+ theme +"/buttonUp_Off.png", 45, 147);
    var buttonDown_OffImage = background.addImageObject("Themes/"+ theme +"/buttonDown_Off.png", 67, 146);
    }


    function OpenURL(url){
    System.Shell.execute(url);
    }
    function NewPostsClick(){
    System.Shell.execute("http://thevistaforums.com/index.php act=Search&CODE=getnew");
    }
    function WikiClick(){
    System.Shell.execute("http://thevistaforums.com/index.php autocom=ineo");
    }
    function ControlPanelClick(){
    System.Shell.execute("http://thevistaforums.com/index.php act=UserCP&CODE=00");

    }
    function buttonUpClick(){
    rssPage-=3;
    if(rssPage <= 0)
    rssPage=0;

    buildPage(rssPage);
    }
    function buttonDownClick(){
    rssPage+=3;
    if(rssPage > rssCount-3)
    rssPage = rssCount-3;

    buildPage(rssPage);
    }

    function buildPage(pageNo)
    {
    var rXML = responseData;
    gRSS.innerHTML ="";

    var nl = rXML.getElementsByTagName('item');
    for( var i = 0; i < nl.length; i++ ) {
    if(i >=pageNo){
    var nli = nl.item(i);
    var title = new String(nli.getElementsByTagName('title')[0].text);
    var link = nli.getElementsByTagName('link')[0].text;
    var pubDate = nli.getElementsByTagName('pubDate')[0].text;
    var d = new Date(pubDate);
    if(title.length > 17)
    title = title.substring(0,17) +"...";
    var onC ="OpenURL('"+link+"')";
    var RSSRow = "<div onclick=\""+onC+"\" class=\"RSSRow\"><div class=\"RSSHeader\">"+title+"<div class=\"RSSDate\">"+d.toLocaleDateString()+"</div></div></div>"
    rssCount = nl.length;
    if(i== pageNo+3)
    i=nl.length;
    gRSS.innerHTML += RSSRow;
    }
    }
    }
    </script>
    </head>
    <body>
    <div>
    <g:background id="background" style="position:absolute; z-index:-999" />
    <div id="gHeaderText" style="position:absolute; left:19; top:8"></div>
    <div id="gRSSFeed" style="position:absolute;">
    <div id="gRSS"></div>
    <div>
    <div onclick="NewPostsClick();" id="gNewPostsText" style="position:absolute;">Latest Posts</div>
    <div onclick="WikiClick();" id="gWikiText" style="position:absolute;">WiKi</div>
    <div onclick="ControlPanelClick();" id="gControlPanelText" style="position:absolute;">Control Panel</div>
    <div onclick="buttonUpClick();" id="gbuttonUp" style="position:absolute;"></div>
    <div onclick="buttonDownClick();" id="gbuttonDown" style="position:absolute;"></div>
    </div>
    </body>
    </html>

    As you may see most of the work is done in this section

    _________________________________________________________________________

    window.onload = function(){
    LoadThemeSettings();
    gRSS.innerHTML = "<img src=themes/"+theme+"/16-on-black.gif> Reading Posts...";

    System.Gadget.settingsUI = "Theme.html";
    System.Gadget.onSettingsClosed = SettingsClosed;
    PaintScreen();
    var oLoad = setTimeout(oLoado, 500);
    }__________________________________________________________________________

    The problem is this section is only performing once as are the links in the body section, once the refresh happens all the links die.

    Also I'd like to be able to change stylesheet based on the theme (I have 8 so far), obviously if I change the 'var theme ="TheVistaForums";' to be in front of the stylesheet definition I should then be able to use the "theme" variable to define the stylesheet location, but how

    Thanks for any help


  • Dan F. Jansson

    I beleive you should be able to use the following to tell it not to cache. I'm not sure though.

    XMLHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");

    Change "XMLHttp" to whatever your using

  • mstcrow5429

    "location.href = location.href;" is the only reliable method to refresh the whole gadget. Set it up an an interval timer:

    window.setInterval(refreshGadget, 10000);
    ...

    function refreshGadget() {
    location.href = location.href;
    }

  • ro88o

    Thanks Jonathan. Does that code go in the gadget.xml file, or in the html file I'm a bit of a newbie at this.
  • HKEC

    ...or you can add something random to the end of the IFRAME url:

    url + " zzz='' + Math.random();

  • rogupta

    I had exactly the same problem, which I could not solve by adding a querystring to the image-source (as the Sidebar gadget would then display the annoying red X as it could not find the image when I'd add the to it. I therefor just set the image-source to an empty string first ("") and after that I made the gadget show the "real source" again. That works fine! I gave this answer before to another post, so just see this post about the same subject. Hope this helps.
  • abhishek_6023

    It needs to go into either the <HEAD> section, or your JS file - if you have one.

    eg.

    <HEAD>
    <SCRIPT language="javascript" type="text/javascript">
    ...
    </SCRIPT>
    </HEAD>

  • Web Site in sidebar Gadget; Need to Refresh Every 10 Seconds