About

js: разное


Заменить все вхождения в строку:

html = html.replace(/<input/g, "<input disabled='disabled'");

Открыть окно:

var winPrint = window.open("print", "_blank");
winPrint.document.write('<html> .... </html>);
winPrint.document.close();

Скрипт для ie < 9

<!--[if lt IE 9]>
<script src="resources/js/ie/ie_commons.js"></script>
<![endif]-->


Скрипт для ie >=9 и прочих браузеров

<!--[if !lt IE 9]> -->
 <script.../>
<!-- <![endif]-->


Получить следующий элемент.
element.nextElementSibling -- работает во всех кроме ie < 9
Универсальный метод:
var getNextElement = 
        document.documentElement.nextElementSibling !== undefined ?
        function(elem) {
            return elem.nextElementSibling;
        } 
        :
        function(elem) {
            var current = elem.nextSibling;
            while (current && current.nodeType != 1) {
                current = current.nextSibling;
            }
            return current;
        };

Длина текста в пикселях:
 var ctx = canvasEl.getContext("2d");
 var windth = getWidthTextPx(ctx, "some textttt");
 ...
 getWidthTextPx: function(ctx, text) {
        var textWidth = ctx.measureText(text).width;
        return textWidth;
    }


Статья неубиваемые куки
Помнить о событии oninput и onpropertychange для ie.