Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Auto refreshing Javacript coding every minute

    Firstly I need to say that I am at beginners level with Javascript!
    So I have some coding on my Wordpress site for a Radio Station, which basically displays the song now playing in a widget.

    Sadly the code does not change with the song, unless you refresh the page.
    Is there a way to refresh the page or widget with another piece of coding?

    My current code is below.

    Thanks in advance

    [CODE]<span id="mav_nowplaying"></span>
    <script type="text/javascript" src="http://www.makeavoice.com/shoutcast2/snippets/nowplaying.php?ip=87.117.201.166&amp;port=8200&amp;streamtitle=yes&amp;streamsong=yes&amp;streamlist eners=no&amp;streammaxlisteners=no&amp;streambitrate=no&amp;streamtitlecolor=000000&amp;streamsongco lor=4C0099&amp;streamlistenerscolor=FFFFFF&amp;streammaxlistenerscolor=FFFFFF&amp;streambitratecolor =FFFFFF&amp;streamtitlesize=3&amp;streamsongsize=2&amp;streamlistenerssize=-1&amp;streammaxlistenerssize=-1&amp;streambitratesize=-1" language="javascript"></script>[CODE]

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    One easy way: Put that script in an <iframe> and then reload the <iframe> every minute.

    Code:
    <span id="mav_nowplaying"></span>
    <iframe id="showplaying" src="xyz.html"></iframe>
    <script type="text/javscript">
    setInterval(
        function( ) {
            document.getElemementById("showplaying").src = "xyz.html?" + Math.random();
       },
       60000
    );
    </script>
    And of course the file "xyz.html" simply consists of the <script> you showed.

    The Math.random is there to ensure that the browser doesn't try to aggressively cache the xyz.html contents.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brilliant - thanks for your response.

    I just need to check - after the src tag, am I adding the whole script that I posted, or from the web address? Also, do I copy until the "javascript" at the end?

    Apologies, I really am a novice! CSS I can do, but this is all new to me!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    > after the src tag, am I adding the whole script that I posted , or from the web address

    Neither.

    You need to make *ANOTHER* HTML page (the one I named "xyz.html", but name it whatever you wish, of course).

    And it will be something like:
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script type="text/javascript"
     src="http://www.makeavoice.com/shoutcast2/snippets/nowplaying.php?ip=87.117.201.166&amp;port=8200&amp;streamtitle=yes&amp;streamsong=yes&amp;streamlist eners=no&amp;streammaxlisteners=no&amp;streambitrate=no&amp;streamtitlecolor=000000&amp;streamsongco lor=4C0099&amp;streamlistenerscolor=FFFFFF&amp;streammaxlistenerscolor=FFFFFF&amp;streambitratecolor =FFFFFF&amp;streamtitlesize=3&amp;streamsongsize=2&amp;streamlistenerssize=-1&amp;streammaxlistenerssize=-1&amp;streambitratesize=-1">
    </script>
    </body>
    </html>
    And *THAT* is the file/web page that gets loaded into the <iframe>.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah, okay that makes sense!

    I created the html file, uploaded it to the server but I'm just getting a blank box?
    The URL is http://www.glossop.biz and I'm trying to add it to the top right widget.

    Would there be anything that I've missed?

    Sorry and thanks!

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    Well, on that URL you certainly aren't using any part of my suggestion, so I don't know what it is you want me to look at.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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