Home  >  Article  >  Web Front-end  >  How to get html based on specified clipboard?

How to get html based on specified clipboard?

零下一度
零下一度Original
2017-04-28 15:15:041845browse

Get html from the specified clipboard. This is a little tricky. Let’s take a look at the code.

    /**
     * 从指定的剪切板中获取html
     * @param clipboard
     * @return
     * @throws Exception
     */
    public static String getClipboardHtml(Clipboard clipboard) throws Exception {
        if(clipboard == null){
            clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();//获取系统剪贴板
        }
        // 获取剪切板中的内容
        Transferable clipT = clipboard.getContents(null);
        if (clipT != null) {
            DataFlavor dataFlavor = new DataFlavor("text/html;class=java.lang.String");
            return String.valueOf(clipT.getTransferData(dataFlavor));
        }
        return null;
    }

The above is the detailed content of How to get html based on specified clipboard?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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