JavaScript-what is in your clipboard when you copy a webpage?

Source: Internet
Author: User
Keywords c c++ vb.net javascript php
Sorry, I do not know this question to which column to ask, in that programming language plate, I will all ask, always have to understand the person!

For example, I copy the content of a Web page, which has text, there are pictures,

If you paste him into a *.txt, he will paste it out as a pure string;

If you paste him into a Word document, he is a good version of the text containing HTML tags and CSS styles;

If you paste him into the QQ Chat window, is the picture + string,

I don't understand what the hell is going on in my clipboard?

What is this thing coded for?

In fact, to ask the purpose of this is to re-encode the Clipboard.




Reply content:

Sorry, I do not know this question to which column to ask, in that programming language plate, I will all ask, always have to understand the person!

For example, I copy the content of a Web page, which has text, there are pictures,

If you paste him into a *.txt, he will paste it out as a pure string;

If you paste him into a Word document, he is a good version of the text containing HTML tags and CSS styles;

If you paste him into the QQ Chat window, is the picture + string,

I don't understand what the hell is going on in my clipboard?

What is this thing coded for?

In fact, to ask the purpose of this is to re-encode the Clipboard.




HTML bar of the Web page, notepad++ has the option to paste as HTML


You can understand that what you're copying is an object, and what it looks like is what the target software gets from your object.


It's essentially a binary.
On Windows, you can directly remove audio, image, or text objects by calling different methods
page, it should be a string to take out

If you are using. NET, you can use the System.Windows.Clipboard class
When you copy a Web page, Clipboard.gettext (textdataformat.html) should be able to remove the Html string
Specific reference msdn:https://msdn.microsoft.com/zh-cn/library ...


Feel the Clipboard inside is your Web page HTML, text, pictures and other content, because you select a part of the page, with F12 open debugging, you can see in the HTML code, the corresponding code part is also selected, and Notepad only display plain text, because it can not read the image links and HTML tags, etc. World document can read the image path, QQ is the same


For the Web page, the copy should be the selected part of the HTML source, as for the output will be output when it is the interpretation of the software you use. Similarly, if you copy a file and then paste it into Word, it is a reference, and pasting it into a text box is a file name, and if you copy multiple lines of text pasted into a single-line text box, you may keep only the first line, or all newline characters will be discarded and merged into one line.


The Clipboard is removed and pasted is a memory variable in the course of a program's operation.
The difference is that your target program has a different ability to read it.


Good coincidence, yesterday I also want to get something, the Clipboard contents are reversed and then output, but encountered is a variety of coding problems, as well as the conversion of the picture. Mark down and see.


I've written before, "How many shears are there in your notebook?" 》。 But I don't know how this clipboard works. Search the Stack Overflow, this link may help: Clipboard Operations (Windows). Under Paste Operations said, the system Clipboard can be exported to different formats, a window can set their own paste format, such as Notepad can only get text content, and Word can also get the picture in it, even text format, and so on.

, we have to mention that different operating system of the Clipboard is not the same. For example: Under Linux to copy a file, in fact, copied the file path ... It's much different from what's happening on Windows.

With regard to the Clipboard, all the answers may be given here: Hluk/copyq:clipboard Manager with the advanced features. The installation tried, the effect is good, from Word and the page copy of things can be very good display:

Some other reference links:

    • Copy a piece of text from the browser and paste it into the Evernote client (Windows), why does Evernote get the URL of the original page? Is there no security problem? -Ge Gioriang's answer--know


A data structure is stored.
See also: Windows API settings Clipboard contents


The following is discussed for Win32. @aristotll the answer to the notepad++ of the selective paste, so I retrace, found the corresponding source code, excerpt as follows:

Case Idm_edit_paste_as_rtf:case idm_edit_paste_as_html:{    longrunningoperation op;    UINT f = RegisterClipboardFormat (id==idm_edit_paste_as_html? CF_HTML:CF_RTF);    if (! Isclipboardformatavailable (f))        return;    if (! OpenClipboard (NULL))        return;    Hglobal hglb = GetClipboardData (f);    if (hglb! = NULL)    {        LPSTR lptstr = (LPSTR) globallock (HGLB);        if (lptstr! = NULL)        {            //Call the application-defined replaceselection            //function to insert the text and R Epaint the            //window.            _peditview->execute (Sci_replacesel, 0, (LPARAM) lptstr);            GlobalUnlock (HGLB);        }    }    CloseClipboard ();} Break

It can be seen that the Clipboard format is not a finite type, but can be defined by RegisterClipboardFormat (). For more details, refer to the information on MSDN.


The Clipboard is a piece of the computer disk area (previously learned Computer Foundation encountered), should be binary, paste to see the software support, such as the Web page access to the Clipboard is limited, qq,office these are local software, the permissions are higher so the content is fully transparent access

  • 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.