chrisbailey

re-enabling onpaste method

Dec 30th, 2012
3,840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  Following code overrides the disabling of onpaste methods.
  3.  Based on code from:
  4.  http://prioritized.net/blog/re-enabling-password-pasting-on-annoying-web-forms/
  5.  Note: Only works in Chrome & Safari
  6. */
  7.  
  8. var inputs=document.getElementsByTagName('input');
  9. for(var i=0;i<inputs.length;i++)
  10. {
  11.   if(inputs[i].getAttribute('type').toLowerCase()==='password')
  12.   {
  13.     inputs[i].onpaste = function(e) {
  14.       // only Chrome and Safari support clipboardData access on event object
  15.       // see http://codebits.glennjones.net/editing/getclipboarddata.htm
  16.       if (e.clipboardData != undefined && e.clipboardData.getData != undefined)
  17.       {
  18.         this.value = e.clipboardData.getData('text/plain');
  19.       }
  20.       return false;
  21.     }
  22.   }
  23. }
RAW Paste Data