Tom Studer's Home Page
[ start | index | login ]
start > HTML Stuff

HTML Stuff

Created by tom. Last edited by tom, 3 years and 186 days ago. 被访问了 442 次。 #7
[比较] [历史] [编辑] [rdf]
标签
附件

2D DHTML Object Drawing JavaScript library

Caret/cursor position in INPUT text field or TEXTAREA

The following JavaScript method determines the current caret position for the passed input text field or textarea. The code is IE specific. Tested for IE 6.

function caretPosition(textfield) {
    textfield.focus();
    if (textfield.type == 'textarea') {
        var range = document.selection.createRange();
        var range2 = range.duplicate();
        range2.moveToElementText(textfield);
        var bookmark = range.getBookmark();
        var bookmark2 = range2.getBookmark();
        return bookmark.charCodeAt(2) - bookmark2.charCodeAt(2); 
    } else { // Assume input field of type text
        var range = document.selection.createRange();
        range.moveStart ('character', -textfield.value.length);
        return range.text.length;
    }
}
Thanks, Mihai, for the bookmark trick. (See >>http://www.bazon.net/mishoo/articles.epl?art_id=1292)

JavaScript Widgets

A great looking JavaScript widgets library (commercial): >>http://www.activewidgets.com/

Web Page Printing

In the stylesheet:

@media print {
  .noprint {display: none;}
  .contentwidth1000 {width: 100%;}
}

@media screen { .contentwidth1000 {width: 1000;} }

In your HTML code, hide stuff on the printout like:

<div class="noprint">
…
</div>

An A4 page is only about 640 pixels wide (default IE margins). Thus you may have to adjust the width of certain elements. For example, instead of:

<td width="1000">...</td>

Do it like this:

<td class="contentwidth1000">...</td>

For the actual printing, use a link like:

<a href="#" onClick="window.print(); return false">Print</a>

no comments | post comment
mouse_cartoon



< February 2012 >
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
26272829

snipsnap-help | More Help

Powered by SnipSnap 1.0b2-uttoxeter

Describe here what your SnipSnap is about!

Configure this box!

  1. Login in
  2. Click here: snipsnap-portlet-2
  3. Edit this box
snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt