Results 1 to 2 of 2
  1. #1
    crisfromnova is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default How to simulate browser CTRL+F function

    Hi all,

    I use in my program an instance of swt Browser and I want to make a custom search. So I use setEnabled(false) to disable native CTRL+F function and I have a Text and a Button which I want to use its for searching a word in text displayed in browser. There is a way to simulate CTRL+F and get the text searched or the position?

    Thanks in advance!

  2. #2
    crisfromnova is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default Solution

    For that can be used the next jvascript function :


    var NS4 = (document.layers);
    var IE4 = (document.all);
    var win = window;
    var n = 0;
    function findInPage(str) {
    var txt, i, found;
    if (str == "")
    return false;
    if (NS4) {
    if (!win.find(str))
    while(win.find(str, false, true))
    n++;
    else
    n++;
    if (n == 0)
    alert("Not found.");
    }
    if (IE4) {
    txt = win.document.body.createTextRange();
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
    txt.moveStart("character", 1);
    txt.moveEnd("textedit");
    }
    if (found) {
    txt.moveStart("character", -1);
    txt.findText(str);
    txt.select();
    txt.scrollIntoView();
    n++;
    }
    else {
    if (n > 0) {
    n = 0;
    findInPage(str);
    }
    else
    alert("Sorry, we couldn't find.Try again");
    }
    }
    return false;
    }

Similar Threads

  1. Simulate a Network using Java
    By fung1223 in forum New To Java
    Replies: 0
    Last Post: 01-13-2010, 11:46 AM
  2. Replies: 3
    Last Post: 12-04-2009, 04:08 PM
  3. Replies: 0
    Last Post: 07-25-2008, 03:26 PM
  4. simulate form type=button press with java application
    By redmoonzer01 in forum Networking
    Replies: 1
    Last Post: 03-29-2008, 07:28 AM
  5. simulate message box
    By pablitohh in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •