[Js]javascript interacts with the clipboard _mssql

Source: Internet
Author: User
Tags html tags
1. How to operate the Clipboard, so as to achieve copy, cut and paste? and also to determine if the data inside the Clipboard is text?
if (! Isclipboardformatavailable (Cf_text))
Return
if (! OpenClipboard (Hwndmain))
Return

HGLB = GetClipboardData (cf_text);
if (hglb!= NULL)
{
LPTSTR = GlobalLock (HGLB);
if (LPTSTR!= NULL)
{
Call the application-defined replaceselection
function to insert the text and repaint the
Window.

ReplaceSelection (hwndselected, Pbox, LPTSTR);
GlobalUnlock (HGLB);
}
}
CloseClipboard ();

2. Can I get a string from the Windows clipboard using JavaScript?
For example, in a Web page, click a text box to paste the characters in the Clipboard

Of course
<form>
<p>
<input name=txtsearch value= "" >
<input Type=button value=copy2clip onclick= ' Javascript:var textrange=txtsearch.createtextrange (); Textrange.execcommand ("Copy") ' >
</p>
<p>
<input name= "CopyTo" type= "text" id= "CopyTo" >
<input Type=button value=pastefromclip onclick= ' Javascript:var textrange=copyto.createtextrange (); Textrange.execcommand ("Paste") ' >
</p>
</form>

3.javascript Interaction with the Clipboard

You can generally copy the contents of an object with ID ' ObjID ' to the Clipboard

var rng = Document.body.createTextRange ();
Rng.movetoelementtext (document.getElementById ("ObjID"));
Rng.scrollintoview ();
Rng.select ();
Rng.execcommand ("Copy");
Rng.collapse (FALSE);
settimeout ("window.status=", 1800)

You can also use Rng.execcommand ("Past"); glue the contents of the Clipboard to the current position of the cursor.

Content See the TextRange object for MSDN.

However, copy to the Clipboard is not tagged with HTML, all HTML tags will be filtered.


4.window.clipboarddata.getdata ("text")//can get the text of the Clipboard
Window.clipboardData.setData ("text", "Your Content")//write text messages to clipboard

5. How can I tell if the data in the Clipboard is a string rather than a picture or other information?

Private Sub Command1_Click ()
If Clipboard.getformat (Vbcftext) Or Clipboard.getformat (vbcfrtf) Then
MsgBox "OK"
End If
End Sub





6. How can I tell if the Clipboard is not empty?


One

Eg
To determine if the Windows Clipboard is empty, not to read the picture to the image
Uses CLIPBRD;

If Clipboard.hasformat (cf_picture) Then
Image1.Picture.Assign (ClipBoard);
Two

Uses CLIPBRD;

Procedure Tform1.button1click (Sender:tobject);
Begin
If Clipboard.formatcount <= 0 Then
{TODO: null};
End



7. How do I determine if the data in the Clipboard is an image?


GetFormat Method Example
This example uses the GetFormat method to determine the format of the data on the Clipboard object. To verify this example, paste the example code into the Declarations section of a form, and then press F5 and click the form.

Private Sub Form_Click ()
' defines various formats for bitmaps.
Dim clpfmt, MSG ' declare variable.
On error Resume Next ' to set the wrong handling.
If Clipboard.getformat (vbcftext) Then clpfmt = clpfmt + 1
If Clipboard.getformat (vbcfbitmap) Then clpfmt = clpfmt + 2
If Clipboard.getformat (vbcfdib) Then clpfmt = clpfmt + 4
If Clipboard.getformat (vbcfrtf) Then clpfmt = clpfmt + 8
Select Case CLPFMT
Case 1
MSG = "The Clipboard contains only text."
Case 2, 4, 6
MSG = "The Clipboard contains only a bitmap."
Case 3, 5, 7
MSG = "The Clipboard contains text and a bitmap."
Case 8, 9
MSG = "The Clipboard contains only rich text."
Case Else
MSG = "There is no on the Clipboard."
End Select
MsgBox Msg ' displays information.
End Sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.