Log In or Sign Up

Snippets — Tagged with 'Firefox'

Fake 'onpaste' Event in Firefox

Tags:
Firefox, browsers, onpaste, pasting
Posted by:
Michael Bleigh 8 months ago

This takes attribute-based ‘onpaste’ events that work in IE and Safari and makes them (mostly) work in Firefox as well. More Detail Here

  function checkForPaste(event) {
    var e = event.element();
    if ((e.previousValue && e.value.length > e.previousValue.length + 1) ||
        (!e.previousValue && e.value.length > 1)) { 
      if (e.onpaste) {
        e.onpaste(e)
      } else if (e.readAttribute("onpaste")) {
        eval(e.readAttribute("onpaste"));
      }
    }
      e.previousValue = e.value;
  }

  function firefoxOnPaste() {
    $$('textarea').each(function(e) { 
      if (e.onpaste || e.readAttribute("onpaste")) {
        Event.observe(e,'input',checkForPaste);
      }
    });
  }

  if (Prototype.Browser.Gecko) {
    document.observe('dom:loaded', firefoxOnPaste);
  }