25 lut 2009

Współrzędne myszki, pozycja kursora myszki Javascript

<html>
  <head>
    <script type="text/javascript">
      var IE = document.all ? true : false;
      if (!IE) document.captureEvents(Event.MOUSEMOVE);
      document.onmousemove = myMouseXY;
      var pX = 0;
      var pY = 0;
      function myMouseXY(e) {
        if (IE) {
          pX = event.clientX + document.body.scrollLeft;
          pY = event.clientY + document.body.scrollTop;
        } else {
          pX = e.pageX;
          pY = e.pageY;
        }
        if (pX < 0) pX = 0;
        if (pY < 0) pY = 0;

        document.getElementById("ws").value = pX + ',' + pY;
        document.getElementById("dymek").style.left = pX;
        document.getElementById("dymek").style.top = pY;
        return true;
      }
    </script>
  </head>
  <body>
    <div id="dymek" style="position: absolute;">
      <input type="text" id="ws">
    </div>
  </body>
</html>
17 lut 2009

Kolorowanie rekordów w tabeli

Przypisanie zdarzeń do tagów

tabeli

<script>
  function add_tr_hover(id) {
    alert(id);
    var elem = document.getElementById(id);
    var lista = elem.getElementsByTagName('tr');
    for (var i = 0; i < lista.length; i++) {
      lista[i].onmouseover = function () { this.style.backgroundColor = '#EDEDED'; }
      lista[i].onmouseout = function () { this.style.backgroundColor = '#FFFFFF'; }
    }
  }
  window.onload = function () {
    add_tr_hover("cos");
  }
</script>

Przykładowy HTML tabeli

<table id="cos">
  <tr>
    <TD>jeden</TD>
  </tr>
  <tr>
    <TD>dwa</TD>
  </tr>
  <tr>
    <TD>trzy</TD>
  </tr>
  <tr>
    <TD>cztery</TD>
  </tr>
  <tr>
    <TD>pięć</TD>
  </tr>
</table>
13 gru 2008

Drukowanie fragmentu strony

function print_frag(id) {
  var div;

  div = document.getElementById(id);
  okno = window.open("", "", "toolbar=0, location=0, resizable=1, directories=0, status=1, menubar=1, scrollbars=1, height=800, width=700, top=80, left=350");
  var html = div.innerHTML;

  html = '<html><head><link rel="stylesheet" href="<a href="http://kody.wig.pl/style.css" class="mce_ws_kod">http://kody.wig.pl/style.css</a>" type="text/css" /></head><body>' + html + '</body></html>';

  okno.document.write(html);
  //okno.print();
  okno.focus();
}
<a href="javascript:print_content('fragment')">Drukuj</a>