开发者

Is there a way to capture x-browser paste events in mootools?

开发者 https://www.devze.com 2022-12-19 03:38 出处:网络
I want to capture when a user pastes data into a text input field using mootools event system. 开发者_运维问答

I want to capture when a user pastes data into a text input field using mootools event system.

开发者_运维问答

Anyone have experience of this?


The paste event has become better supported in recent times: IE has had it since around 2000 (IE 5.5, I think), Firefox since 3.0, WebKit for a couple of years (not sure exactly when). You should use it where possible and fall back to detecting ctrl-v or shift-ins in other cases, or polling the input box's value using a timer.


The function will get fired whenever the keys 'ctrl+v' are pressed.

Mootools docs : http://www.mootools.net/docs/more/Interface/Keyboard

EDIT : HTML and JS Code

<html>
    <head>
        <script type='text/javascript' src='core.js'></script>
        <script type='text/javascript' src='more.js'></script>
        <script type='text/javascript'>
        function keyPressed(e)
        {
            var evt = Event(e);
            evt.stop();
        }

        window.addEvent('domready', function()
        {
            var myKeyboardEvents = new Keyboard(
            {
                eventType: 'keyup', 
                events: 
                { 
                    'ctrl+v': keyPressed
                }
            });

            myKeyboardEvents.activate()

        });
        </script>
    </head>
    <body>
        <form id='myForm'>
            <input type='text' name='some' id='username' value='stack@over.com'/>
        </form>
    </body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消