www.webdeveloper.com
Results 1 to 1 of 1

Thread: Reload page if there is new content.

  1. #1
    Join Date
    Jul 2010
    Posts
    17

    Reload page if there is new content.

    Help i have the following code which shows the cd cover of the song that plays in my website. This image reload every 30 secont.

    That i want is every 30 secont to check if the image change and if he change he will refresh it if not the image will not refresh. (Sorry for my English)

    Code:
    jQuery(document).ready(function() {
        pollstation();
        setInterval(pollstation, 30000);
    });
     
    function requestCrossDomain( callback ) {  
        var yql = 'yql.php?callback=?';
        jQuery.getJSON( yql, cbFunc );
     
        function cbFunc(data) {  
        if ( data ) {  
            data = data[0].results.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
            data = data.replace(/<html[^>]*>/gi, '');
            data = data.replace(/<\/html>/gi, '');
            data = data.replace(/<body[^>]*>/gi, '');
            data = data.replace(/<\/body>/gi, '');
     
            if ( typeof callback === 'function') {  
                callback(data);  
            }  
        }  
        else throw new Error('Nothing returned from getJSON.');  
        }  
    }  
     
    function pollstation() {
        requestCrossDomain(function(stationdata) {
            var lines = stationdata.split('<br/>');
     
    		jQuery('#cdcover').html('<img width="90" height="90" title="" src="/live/pic/cd_cover/' + encodeURIComponent(jQuery.trim(lines[1])) + '.jpg" border=0 alt=""/>');
    		
        } );
    }
    Here is the code of html.

    Code:
    <html>
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title></title>
    
    <script src="jquery.min.js" type="text/javascript"></script>
    <script src="videos2.js" type="text/javascript"></script>
    
    </head>
    <body style= leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    
    <div style="width: 366px; height: 223px;" id="cdcover"></div>
    
    </body>
    </html>
    Last edited by dj_kostas_pro; 08-18-2012 at 02:09 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles