2013年1月7日 星期一

Google url shortener

Google url shortener 可以生產出短網止,也可生產出QR code

Get the MD5 code


private string HashString(string Value)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
        data = x.ComputeHash(data);
        string ret = "";
        for (int i = 0; i < data.Length; i++)
            ret += data[i].ToString("x2").ToLower();
        return ret;
    }

2012年12月28日 星期五

window.location.Reload() and window.location.href=window.location.href; difference

window.location.Reload() is refresh page, it will submit the data again and has a alert message is continue.

window.location.href=window.location.href is redirect url.

2012年11月21日 星期三

Get screen width Javascript


<script type="text/javascript" language="javascript">
    if (document.getElementById("rightMenu") != null) {
        if (screen.width < 1200) {
            document.getElementById("rightMenu").style.display = "none";
        }
    }

</script>

position fixed for IE6

Add this code in the header

<!--[if IE 6]>
<style type="text/css">
.promomenu{
position:absolute; /* position fixed for IE6 */
top:expression(200+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px');
right:expression(0+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px');
}
</style>
<![endif]-->

2012年9月20日 星期四

日期時間倒數器


  <SCRIPT type="text/javascript" language="javascript">
      var startDate = new Date();
      var endDate = new Date(2012, 8, 20, 10, 00);
      var spantime = (endDate - startDate) / 1000;

      function getString(dt) {
          return dt.getFullYear() + "?" + (dt.getMonth() + 1) + "?" + dt.getDate() + "?" + dt.getHours() + "?" + dt.getMinutes() + "?";
      }
      function leftPad(n, len) {
          return (new Array(len - String(n).length + 1)).join("0").concat(n);
      }
      function cal() {
          spantime--;
          var d = Math.floor(spantime / (24 * 3600));
          var h = Math.floor((spantime % (24 * 3600)) / 3600);
          var m = Math.floor((spantime % 3600) / (60));
          var s = Math.floor(spantime % 60);
          str = d + "? " + h + "?" + m + "? " + s + "? ";



          document.getElementById("hours2").innerHTML = leftPad(h, 2);
          document.getElementById("min2").innerHTML = leftPad(m, 2);
          document.getElementById("sec2").innerHTML = leftPad(s, 2);
          if (document.getElementById("hours3") != null) {
              document.getElementById("hours3").innerHTML = leftPad(h, 2);
              document.getElementById("min3").innerHTML = leftPad(m, 2);
              document.getElementById("sec3").innerHTML = leftPad(s, 2);
          }

      }

      window.onload = function () {
          setInterval(cal, 1000);
      }
</SCRIPT>