topical media & game development

talk show tell print

basic-javascript-14-MessageOfTheDay-motd.htm / htm

      <title>Message of the Day</title>
      <script type="text/javascript">
      function createDocument() 
          //Temporary DOM object.
          var xmlDoc;
          //Create the DOM object for IE
          if (window.ActiveXObject) 
              var versions = 
              for (var i = 0; i < versions.length; i++) 
                      xmlDoc = new ActiveXObject(versions[i]);
                      return xmlDoc;
                  catch (error) 
                      //do nothing here
          //Create the DOM for Firefox and Opera
          else if (document.implementation && document.implementation.createDocument) 
              xmlDoc = document.implementation.createDocument("","",null);
              return xmlDoc;
          return null;
      //Gets the message from the XML file
      function getDailyMessage() 
          //Get the node list of <daily/> elements.
          var messages = xmlDoc.getElementsByTagName("daily");
          //Create a date object.
          var dateobj = new Date();
          //And get today's day.
          var today = dateobj.getDay();
          //Return the message.
          return messages[today].firstChild.nodeValue;
  <div id="messageContainer"></div>
  <script type="text/javascript">
      //Create the DOM object
      var xmlDoc = createDocument();
      //We'll load it in synchronous mode.
      xmlDoc.async = false;
      //Load the XML file
      document.getElementById("messageContainer").innerHTML = getDailyMessage();

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.