0

I am developing a java application using SWT. It has a browser embeded in it.I have to add copy,selectall,find functions to this app.I have used this script to implement copy function

final String SCRIPT01 = "var html = \"\";"+
                "if (typeof window.getSelection != \"undefined\") {"+
                    "var sel = window.getSelection();"+
                    "if (sel.rangeCount) {"+
                        "var container = document.createElement(\"div\");"+
                        "for (var i = 0, len = sel.rangeCount; i < len; ++i) {"+
                            "container.appendChild(sel.getRangeAt(i).cloneContents());"+
                        "}"+
                        "html = container.innerHTML;"+
                    "}"+
                "} else if (typeof document.selection != \"undefined\") {"+
                    "if (document.selection.type == \"Text\") {"+
                        "html = document.selection.createRange().htmlText;"+
                    "}" +
                "}" +
                "return html";

I actually found this code on SO and i have no idea what this is.But it worked for me.Can anyone tell what script it is.I thought it was javascript but i think im wrong and any links to tutorials of this script will be very useful.I want to learn this script and see if i can use it to implement "select all" and "find" functions.

user3873909
  • 191
  • 1
  • 3
  • 15

1 Answers1

0

Yes. That is pure javascript. Since java won't execute on browser, we need javascript for that.

I want to learn this script and see if i can use it to implement "select all" and "find" functions.

Jquery library is there for you. Not need to implement on your own.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • So can i use Jquery to impleent search function on the embedded browser in the java application.I have used Browser widget of SWT. – user3873909 Aug 04 '14 at 06:08
  • @user3873909 Yes. Add jquery library to your scripts and proceed. – Suresh Atta Aug 04 '14 at 06:09
  • @SURESH ATTA How do i add the Jquery library? Please answer this http://stackoverflow.com/questions/26417811/running-jquery-script-in-swt-browser – user3873909 Oct 17 '14 at 04:38