top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

In Java Script how to write a function while i pasting some thing?

0 votes
419 views

I need to execute some function while pasting in web page. Can any tell me to solve this issue?This can be possible in Java Script or Jquery?

posted Jul 4, 2014 by Sidharth Malhotra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You cau use onpaste event in javascript will execute a function while pasting.

This event will occur before the contents of the clipboard are pasted into the document.

Actions that invoke the onpaste event:

1)Pressing CTRL + V.
2)Selecting the Paste command from the Edit menu.
3)Opening the context menu (right mouse button) and selecting the Paste command.

Example Code

<head>
    <script type="text/javascript">
        function OnPaste () {
            alert("This is a Paste event example");
        }
    </script>
</head>
<body>
    Select some text, copy it to the clipboard and try to paste it to the following fields:
    <br /><br />
    <input type="text" size="40"  />
    <br /><br />
    <input type="text" size="40"  onpaste="return OnPaste ()" />
</body>

From the above example have two text box.First text box is a normal text box.From that you can enter anything and paste anything normally.

Whereas in the second text box is an example for onpaste event .In this textbox i enabled the onpaste event.So,whenever you paste something in this text box.It will call a onpaste() funciton.In that function i added the alert().So before pasting alert will come.

answer Aug 12, 2014 by Pankaj Deshmukh
Similar Questions
0 votes

Please give the example for both.

+1 vote

Please provide some sample code.I need to take copied data's from clipboard .Any one help me to solve this .

0 votes

I need to execute a function while mouse hover.But i want to execute only when mouse hover for over 2 or 3 seconds.Or else i don't want to execute the function.

0 votes

Also,tell me what are the types of framework are there ?

+1 vote

Please give some example for each.

...