Note. JavaScript cannot access the buffer. Any plugin that does this usually uses Flash in the background.
To capture a copy event, after adding http:// to the input, you need to fire the select event (not the change event). When the value changes, the text is no longer selected, so you need to select a new text after editing it.
To remove http:// from the input field, you can add setTimeout at the end of the event to the reset value.
In addition, you must set $.fn.changevalue outside the callback, it does not need to be reinstalled for each copy event.
$.fn.changevalue = function(v) { return this.val(v).trigger('select'); // this is already a jQuery object } $('#address input').bind('copy', function() { var $this = $(this), origval = $this.val(); $this.changevalue('http://' + origval); setTimeout(function(){ $this.val(origval); }, 0); });
Demo: http://jsfiddle.net/TGHcD/
source share