0

When user paste the text in the text box, the "onpaste"=doPaste() event handler works fine in IE10, but not working in Firefox.

Code: e=event

function doPaste(e) {
    maxLength = 500;
    value = document.getElementById("<%=txtTitle.ClientID%>").value;        
    if (maxLength) {
        if (e.preventDefault)
            e.preventDefault();
        else
            e.returnValue = false;            
        var oTR = document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}

I am missing anything..or is there cross browser fix for this?

Niranjan NT
  • 165
  • 1
  • 19
  • possible duplicate of [HTML: onpaste="doSomething();" as invalid attribute](http://stackoverflow.com/questions/12367417/html-onpaste-dosomething-as-invalid-attribute) – Tim Büthe May 09 '14 at 09:34
  • Try `var sData = (e.clipboardData || window.clipboardData).getData("Text")` – Yury Tarabanko May 09 '14 at 09:35

0 Answers0