Home > Web Front-end > JS Tutorial > body text

DOM_window object attribute--clipboardData object operation code_javascript skills

WBOY
Release: 2016-05-16 18:11:02
Original
1196 people have browsed it

The clipboardData object
provides access to predefined clipboard formats for use in editing operations.

Member table

Method Description
clearData Removes one or more data formats from the clipboard through a dataTransfer or clipboardData object.
getData obtains data in the specified format from the clipboard through dataTransfer or clipboardData objects.
setData assigns data to the dataTransfer or clipboardData object in the specified format.

Example
The following example uses the setData and getData methods of the clipboardData object to perform a cut-and-paste operation through the shortcut menu.

Copy code The code is as follows:

<SCRIPT> <br>var bResult; <br>//Select the text to be cut. Trailing spaces in the text selection during cut events cause the cut <br>// cut selection shortcut menu item to remain disabled. <br>function fnLoad() { <br>var r = document.body.createTextRange(); <br>r.findText(oSource.innerText); <br>r.select(); <br>} <br> <br>// Enable the cut shortcut menu item, which is disabled by default when it is on a DIV <br>function fnBeforeCut() { <br>event.returnValue = false; <br>} <br><br>// Assign data to the window.clipboardData object in text format. <br>// Display the result of the setData method (Boolean) in the input box below. <br>function fnCut(){ <br>event.returnValue = false; <br>bResult = window.clipboardData.setData("Text",oSource.innerText); <br>oSource.innerText = ""; <br> tText.innerText = bResult; <br>} <br><br>// Enable the paste shortcut menu item, which is disabled by default when it is on a DIV <br>function fnBeforePaste() { <br>event.returnValue = false ; <br>} <br><br>// Cancel returnValue in onpaste to enter text. This operation has the default <br>// behavior. <br>function fnPaste() { <br>event.returnValue = false; <br>oTarget.innerText = window.clipboardData.getData("Text"); <br>} <br><br></SCRIPT>


LINK="#000000" VLINK="#808080" ALINK="#000000">

oncut="fnCut()">Select and cut this text

onpaste="fnPaste()">Paste text here



setData Result:




Pay attention to the oncut and onpaste events in the code
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!