onpaste event
Definition and Usage
The onpaste event occurs when the user pastes content into an element.
Although all HTML elements support the onpaste event, it is actually impossible to paste content into, for example, a <p> element unless the element has contenteditable set to "true" (see more examples below).
ਸੁਝਾਅ: The onpaste event is mainly used for <input> elements with type="text".
ਸੁਝਾਅ:You can paste content into an element in three ways:
- CTRL + V
- Select paste from the browser's edit menu
- Right-click menu and select paste command
ਇੰਸਟੈਂਸ
ਉਦਾਹਰਣ 1
When pasting some text into the <input> element, execute JavaScript:
<input type="text" onpaste="myFunction()" value="Paste something in here">
ਉਦਾਹਰਣ 2
When pasting some text into the <p> element, execute JavaScript (note that contenteditable is set to "true"):
<p contenteditable="true" onpaste="myFunction()">Try to paste something inside this paragraph.</p>
ਗਰਿੱਹ
ਜਿਸ ਵਿੱਚ ਐੱਚਟੀਐੱਮਐੱਲ ਵਿੱਚ ਦਰਸਾਇਆ ਗਿਆ ਹੈ:
<element onpaste="myScript">
ਜਿਸ ਵਿੱਚ ਜਾਵਾਸਕ੍ਰਿਪਟ ਵਿੱਚ ਦਰਸਾਇਆ ਗਿਆ ਹੈ:
object.onpaste = function(){myScript};
ਜਿਸ ਵਿੱਚ ਜਾਵਾਸਕ੍ਰਿਪਟ ਵਿੱਚ ਦਰਸਾਇਆ ਗਿਆ ਹੈ, addEventListener() ਮੈਥਡ ਦੀ ਵਰਤੋਂ:
object.addEventListener("paste", myScript);
ਟਿੱਪਣੀ:Internet Explorer 8 ਜਾਂ ਪਹਿਲੇ ਦੀਆਂ ਸੰਸਕਰਣਾਂ ਵਿੱਚ ਸਮਰਥਨ ਨਹੀਂ ਹੈ addEventListener() ਮੈਥਡ。
ਤਕਨੀਕੀ ਵੇਰਵਾ
ਬੁਬਲ ਕਰੋ: | ਸਮਰਥਨ |
---|---|
ਰੱਦ ਕਰਨਯੋਗ: | ਸਮਰਥਨ |
ਈਵੈਂਟ ਟਾਈਪ: | ClipboardEvent |
ਸਮਰਥਿਤ HTML ਟੈਗ: | ਸਾਰੇ HTML ਐਲੀਮੈਂਟ |
ਬਰਾਉਜ਼ਰ ਸਮਰਥਨ
ਈਵੈਂਟ | ਚਰਮੀ | IE | ਫਾਇਰਫਾਕਸ | ਸੈਫਾਰੀ | ਓਪੇਰਾ |
---|---|---|---|---|---|
onpaste | ਸਮਰਥਨ | ਸਮਰਥਨ | ਸਮਰਥਨ | ਸਮਰਥਨ | ਸਮਰਥਨ |