3

Here is the function that i want to use in a web page and want to call it in script node as other javascript functions. But could you please guide me on how to achieve it.

public static String getClipboard() {

    Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

    try {
        if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String text = (String)t.getTransferData(DataFlavor.stringFlavor);
            return text;
        }
    } catch (UnsupportedFlavorException e) {
    } catch (IOException e) {
    }
    return null;
}

I am completely new to this concept.. If you can answer this question, that will be very helpful.. Thanks

11
  • 1
    Do you want to run standar java in the browser? Or am I misinterpreting your question? The browser can only run Javascript. Commented Nov 27, 2011 at 3:55
  • Yes, I dont know that we cannot run Commented Nov 27, 2011 at 3:58
  • Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) That line alone would require a trusted applet. Commented Nov 27, 2011 at 3:58
  • 2
    @MathiasBak "You can not just run Java from a script node." If by 'script node' you mean JavaScript, sure you can. Something like alert(java.lang.System.getProperty("java.version")) should pop the info. on the Java version installed in the browser. Commented Nov 27, 2011 at 4:27
  • 1
    @AndrewThompson does not work for me. can you link to a resource explaining the code? I get Uncaught ReferenceError: java is not defined. Commented Nov 27, 2011 at 5:23

2 Answers 2

1

Use LiveConnect to enable bidirectional communication between Java and JavaScript within a page.

Sign up to request clarification or add additional context in comments.

Comments

1

You can only call interact with Java if it's running on a Java Applet.

If you need to interact with the clipboard in Javascript, this Stack Overflow question answers that for you.

2 Comments

is correct. Apart from that you can execute it at server side using Ajax call and then update DOM accordingly.
@SidCool Sure. I was referring to client side interaction only (which seems to be what the parent poster was interested in).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.