Web Analytics Made Easy -
StatCounter Equivalent of self.find() in IE - CodingForum

Announcement

Collapse
No announcement yet.

Equivalent of self.find() in IE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Equivalent of self.find() in IE

    Does anybody out there know of an equivalent of self.find(), which works only in Netscape, that would work in IE.

    Or to put it in another way, I want to open the "Search in page" dialog box on the click of a button. onClick="self.find()" works fine in NE but not in IE.

    Or a script that would activate the Ctrl F keys would probably do the trick also.

    Thanks
    Daniel

  • #2
    Some links that might help ya'...

    MSDN - findText

    an example

    some code...

    Comment


    • #3
      These are find but if the page is long, the user needs to return to the top of the page to click on the Find button again.

      Isn't there a way to activate the real IE Search in the page button like self.find() does in Netscape? The user is then able to click on F3 to go to the next occurence of his search.
      Daniel

      Comment


      • #4
        I'd like to be able to do the same thing; however, according to this reference, its impossible.

        Here is an example of how to imlement findText in a dialog box, if that helps.

        Comment


        • #5
          Thanks F.N.G. this looks promissing.

          I tried the script in the exemple but something must be wrong as I kept getting error messages. Here is my code.

          Page test.html

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          <title>Test</title>
          </head>
          <body>
          <form><input type="button" value="Search" name="Search" onClick="showModelessDialog('find.html', window,'dialogWidth:385px; dialogHeight:165px; scroll:no; status:no; help:no;');"></form>
          <br>
          <div id="range">
          Leonardo da Vinci was one of the great masters of the High
          Renaissance, especially in painting, sculpture, architecture,
          engineering, and science.<br><br><br>
          Leonardo da Vinci was one of the great masters of the High
          Renaissance, especially in painting, sculpture, architecture,
          engineering, and science.<br><br><br>
          etc.
          </div>
          </body>
          </html>

          Page find.html

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          <title>Find</title>
          <script language="JavaScript">
          // on load create a textrange with everything in my
          // editor object tbContentElement
          var rng = dialogArguments.document.all.tbContentElement.DOM.selection.createRange();

          function window.onunload() {
          dialogArguments.dWin=null; // releases my reference
          }

          // returns a calculated value for matching case and
          // matching whole words
          function searchtype(){
          var retval = 0;
          var matchcase = 0;
          var matchword = 0;
          if (document.all.blnMatchCase.checked) matchcase = 4;
          if (document.all.blnMatchWord.checked) matchword = 2;
          retval = matchcase + matchword;
          return(retval);
          }

          // find the text I want
          function findtext(){
          if (document.all.strSearch.value.length < 1) {
          alert("Please enter text in the \"Find what:\" field.");
          }
          else {
          var searchval = document.all.strSearch.value;
          rng.collapse(false);
          if (rng.findText(searchval, 1000000000, searchtype())) {
          rng.select();
          }
          else {
          var startfromtop = confirm("Your word was not found.\nWould you like to start again from the top?");
          if (startfromtop) {
          rng.expand("textedit"); // selects everything
          rng.collapse(); // collapse at the beginning
          rng.select(); // create the selection
          findtext(); // start again
          }
          }
          }
          }
          </script>
          </head>
          <body bgcolor="ThreeDFace">
          <FORM NAME="frmSearch" method="post" action="">
          <TABLE CELLSPACING="0" cellpadding="5" border="0">
          <TR><TD VALIGN="top" align="left" nowrap style="font-family:Arial; font-size:11px;">
          <label for="strSearch" accesskey="n">Fi<u>n</u>d what:</label><br>
          <INPUT TYPE=TEXT SIZE=40 NAME=strSearch id="strSearch" style="width:280px;"><br>
          <INPUT TYPE=Checkbox SIZE=40 NAME=blnMatchCase id="blnMatchCase">
          <label for="blnMatchCase">Match case</label><br>
          <INPUT TYPE=Checkbox SIZE=40 NAME=blnMatchWord ID="blnMatchWord">
          <label for="blnMatchWord">Match whole word only</label>
          </td>
          <td rowspan="2" valign="top">
          <button name="btnFind" accesskey="f" onClick="findtext();" style="width:75px; height:22px; font-family:Tahoma; font-size:11px; margin-top:15px"><u>F</u>ind Next</button><br>
          <button name="btnCancel" onClick="window.close();" style="width:75px; height:22px; font-family:Tahoma; font-size:11px; margin-top:7px">Close</button><br>
          </td></tr>
          </table>
          </body>
          </html>

          Can you help find what's wrong in this code.

          Thanks again.
          Daniel

          Comment


          • #6
            After pasting & de-spacing the code from that link, I was left with this error: 'dialogArguments' is undefined

            So when I remove this part, the error goes away.
            Code:
            var rng = dialogArguments.document.all.tbContentElement.DOM.selection.createRange();
            
            function window.onunload()
            {
            dialogArguments.dWin=null;
            }
            Obviously the find & replace may not function without this, but since I'm new to all of this, I can't tell you how to fix it.

            Hopefully someone else can provide assistance.

            Comment


            • #7
              Indeed the error goes away, but, as you said, the function doesn't work anymore.

              Thanks anyway
              Daniel

              Comment


              • #8
                Look at this

                Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

                Comment


                • #9
                  That Find in frame is exactly what I was looking for.

                  Thanks a million
                  Daniel

                  Comment


                  • #10
                    Well, I finally got the native dialog to appear... its probably best to put it in an .hta & use it offline, due to the security warning.

                    Here's an example:

                    Code:
                    <html>
                    <head>
                    <title>IE find-dialog</title>
                    
                    <script type="text/javascript">
                    var x;
                    function find()
                    {
                    x = new ActiveXObject("WScript.Shell")
                    x.SendKeys("^f");
                    }
                    </script>
                    
                    </head>
                    <body>
                    <center>
                    
                    <input type="button" value="FIND!" 
                    onclick="find();" />
                    
                    </center>
                    </body>
                    </html>

                    Comment


                    • #11
                      Originally posted by DanLap
                      Thanks F.N.G. this looks promissing.

                      I tried the script in the exemple but something must be wrong as I kept getting error messages. Here is my code.

                      Page find.html

                      var rng = dialogArguments.document.all.tbContentElement.DOM.selection.createRange();
                      Although this issue has come and gone, the likely reason this didn't work is that tbContentElement didn't exist in your main page. It likely would have worked had it been revised to:

                      var rng = dialogArguments.document.body.createTextRange();

                      Comment


                      • #12
                        I tried what you suggested, but got the same "undefined" error as before...

                        Perhaps you can provide a working example?

                        Comment


                        • #13
                          Okay, I put this together.

                          The only thing that I think I changed was an extra line in the find dialog to collapse the selection so that it started searching from the top of the document. Oh, and I changed it so that when you hit the enter key it didn't open up a new window but performed the find.

                          If you're still having problems, let me know which browser you're using...

                          Comment


                          • #14
                            Nice job, thanks!

                            Comment


                            • #15
                              Without revealing too many of my secrets, it is also possible to add replace and replace all functionality to this dialog with relative ease! Jonathan Snook
                              So, are you in the mood to reveal some secrets?

                              Comment

                              Working...
                              X