Results 1 to 4 of 4

Thread: Wow

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    Angry

    When you go to the "Edit" menu in Internet Explorer there is an option to 'Find (On this page) Ctrl + F'....Is there a way that I could possibly invoke this command by pressing a button on my web page (for instance).

    All I need to do is search for a string on the current page.

    I've tried

    window.find();

    And also the variant

    window.find(variable);

    niether work in IE5 but do in Netscape.

    Please help.

    Thanks in advance.

    Matt.

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    here's how to do it in javascript:

    Code:
    <script language="JavaScript"><!--
    var pos = 0;
    function findit() {
        if (document.myform.mytext.value == '') {
            alert('Nothing to search for');
            return;
        }
        if (document.all) {
            var found = false;
            var text = document.body.createTextRange();
            for (var i=0; i<=pos && (found=text.findText(document.myform.mytext.value)) != false; i++) {
                text.moveStart("character", 1);
                text.moveEnd("textedit");
            }
            if (found) {
                text.moveStart("character", -1);
                text.findText(document.myform.mytext.value);
                text.select();
                text.scrollIntoView();
                pos++;
            }
            else {
                pos=0;
                text = document.body.createTextRange();
                text.findText(document.myform.mytext.value);
                text.select();
                text.scrollIntoView();
            }
        }
        else if (document.layers) {
            find(document.myform.mytext.value,false);
        }
    }
    
    if (document.layers || document.all) {
          document.write('<form name="myform">');
          document.write('<input type="text" name="mytext">');
          document.write('<input type="button" value="Find" onClick="findit()">');
          document.write('<\/form>');
    }
    //--></script>
    hope it help

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    Thanks

    Thanks for the information in your reply, it works really well, just another question though, how can I get it to search a different frame??


    Cheers,


    MattJH

  4. #4
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    instead of :

    document.myform.mytext.value

    use:


    parent.frames.yourFrameName.document.myForm.mytext.value

Posting Permissions

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



Click Here to Expand Forum to Full Width