开发者

Problem with first Windows 7 gadget getting javascript to run

开发者 https://www.devze.com 2022-12-28 17:43 出处:网络
For my first windows gadget I\'m trying to make one that displays the current time and date.The code below is what I have, but I can\'t figure out why the javascript is not running.Any ideas?

For my first windows gadget I'm trying to make one that displays the current time and date. The code below is what I have, but I can't figure out why the javascript is not running. Any ideas?

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
    <title>Clock</title>
    <style type="text/css">
      body { width: 130px; height: 60px; margin: 1 1 1 2; }
      body { font-family: Segoe UI, Arial; font-size: 11px; font-weight: bold; white-space: nowrap; }
    </style>
    <script type="text/javascript">
      var background;
      var interval;
      var connection_id;
      var timeZone;
      var now;

      function load() {
        try {
          interval = 1000;
          connection_id = 0;
          timeZone = System.Time.currentTimeZone;

          update();
        }
        catch(e){}
      }

      function update() {
        try {
          now = new Date(Date.parse(System.Time.getLocalTime(timeZone)));
          curDate.开发者_JS百科innerHTML = now.format('M jS, Y');
          curTime.innerHTML = now.format('h:i:s A');
          clearTimeout(connection_id);
          connection_id = setTimeout("update()", interval);
        }
        catch(e) {}
    </script>
  </head>
  <body onload="load()">
    <div id="curDate">
    </div>
    <div id="curTime">
    </div>
  </body>
</html>


I'm not sure what your trying to do with the 'System.Time' references. Try using the JavaScript 'Date' functions. Here is a good reference http://www.w3schools.com/jsref/jsref_obj_date.asp

Also I am not sure if this is just a typo in what you posted but it looks like your missing a closing '}'

 function update() {
    try {
      now = new Date(Date.parse(System.Time.getLocalTime(timeZone)));
      curDate.innerHTML = now.format('M jS, Y');
      curTime.innerHTML = now.format('h:i:s A');
      clearTimeout(connection_id);
      connection_id = setTimeout("update()", interval);
    }
    catch(e) {}
 } // <--- Here


The format method for your date is not a native Date method. Did you define it anywhere? You could try to display the error that is thrown, using curTime.innerHTML = e.message in your catch clause. Check this link on creating sidebar gadgets.

0

精彩评论

暂无评论...
验证码 换一张
取 消