Results 1 to 4 of 4

Thread: Find In Page Script

  1. #1
    Join Date
    Jul 2010
    Posts
    10
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Find In Page Script

    Hello All,

    Does anyone know how to make the FIND IN PAGE Script more compatible to firefox, safari, chrome. And for iphone / ipads etc. I get nothing or I keep getting a 'String _ not found' error message when using my iphone or listed browsers and it works fine with IE.

    Thanks for your help.

    the website is: http://danawallacerealestate.com/sales.html

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Warning: Please include a link to the DD script(s) in question in your post. See this post for more information.


    Works OK-ish on the word 'Ocean' in Firefox here. It appears to be limited to certain sections of the page, depending upon which section has focus. Like if you click in the lower area, it scans the listings. If you click up around the top area, it just scans that area. By click I mean clicking on a spot with no link or button. This might be able to be solved by changing the markup a little.

    Anyways the script is old and never claimed to work in those others. You might try contacting the author. You might be able to use Google to do something like that for you.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    metall5468 (05-22-2011)

  4. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I was looking at this a little more and this version will work in more browsers and also accepts the ENTER key to activate the search in some browsers:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <script type="text/javascript">
    
    /******************************************
    * Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com)
    * Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
    * This notice must stay intact for use
    ******************************************/
    
    //  revised by Alan Koontz -- May 2003
    
    var TRange = null;
    var dupeRange = null;
    var TestRange = null;
    var win = null;
    
    
    //  SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT
    //  http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
    
    var nom = navigator.appName.toLowerCase();
    var agt = navigator.userAgent.toLowerCase();
    var is_major   = parseInt(navigator.appVersion);
    var is_minor   = parseFloat(navigator.appVersion);
    var is_ie      = (agt.indexOf("msie") != -1);
    var is_ie4up   = (is_ie && (is_major >= 4));
    var is_not_moz = (agt.indexOf('netscape')!=-1)
    var is_nav     = (nom.indexOf('netscape')!=-1);
    var is_nav4    = (is_nav && (is_major == 4));
    var is_mac     = (agt.indexOf("mac")!=-1);
    var is_gecko   = (agt.indexOf('gecko') != -1);
    var is_opera   = (agt.indexOf("opera") != -1);
    
    
    //  GECKO REVISION
    
    var is_rev=0
    if (is_gecko) {
    temp = agt.split("rv:")
    is_rev = parseFloat(temp[1])
    }
    
    
    //  USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH
    //  (SELF OR CHILD FRAME)
    
    //  If you want to search another frame, change from "self" to
    //  the name of the target frame:
    //  e.g., var frametosearch = 'main'
    
    //var frametosearch = 'main';
    var frametosearch = self;
    
    
    function search(whichform, whichframe) {
    
    /* //  TEST FOR IE5 FOR MAC (NO DOCUMENTATION)
    
    if (is_ie4up && is_mac) return;
    
    //  TEST FOR NAV 6 (NO DOCUMENTATION)
    
    if (is_gecko && (is_rev <1)) return;
    
    //  TEST FOR Opera (NO DOCUMENTATION)
    
    if (is_opera) return;
    
    //  INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES */
    
    if(whichform.findthis.value!=null && whichform.findthis.value!='') {
    
           str = whichform.findthis.value;
           win = whichframe;
           var frameval=false;
           if(win!=self)
    {
    
           frameval=true;  // this will enable Nav7 to search child frame
           win = parent.frames[whichframe];
    
    }
    
        
    }
    
    else return;  //  i.e., no search string was entered
    
    var strFound;
    
    //  NAVIGATOR 4 SPECIFIC CODE
    
    if(is_nav4 && (is_minor < 5)) {
       
      strFound=win.find(str); // case insensitive, forward search by default
    
    //  There are 3 arguments available:
    //  searchString: type string and it's the item to be searched
    //  caseSensitive: boolean -- is search case sensitive?
    //  backwards: boolean --should we also search backwards?
    //  strFound=win.find(str, false, false) is the explicit
    //  version of the above
    //  The Mac version of Nav4 has wrapAround, but
    //  cannot be specified in JS
    
     
            }
    
    //  NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)
    
    if (win.find) {
       
        if(frameval!=false) win.focus(); // force search in specified child frame
        strFound=win.find(str, false, false, true, false, frameval, false);
    
    //  The following statement enables reversion of focus 
    //  back to the search box after each search event 
    //  allowing the user to press the ENTER key instead
    //  of clicking the search button to continue search.
    //  Note: tends to be buggy in Mozilla as of 1.3.1
    //  (see www.mozilla.org) so is excluded from users 
    //  of that browser.
    
        if (is_not_moz)  whichform.findthis.focus();
    
    //  There are 7 arguments available:
    //  searchString: type string and it's the item to be searched
    //  caseSensitive: boolean -- is search case sensitive?
    //  backwards: boolean --should we also search backwards?
    //  wrapAround: boolean -- should we wrap the search?
    //  wholeWord: boolean: should we search only for whole words
    //  searchInFrames: boolean -- should we search in frames?
    //  showDialog: boolean -- should we show the Find Dialog?
    
    
    }
    
     else if (win.document.body.createTextRange) {
    
      // EXPLORER-SPECIFIC CODE revised 5/21/03
    
      if (TRange!=null) {
    	  
       TestRange=win.document.body.createTextRange();
     
    	  
    
       if (dupeRange.inRange(TestRange)) {
    
       TRange.collapse(false);
       strFound=TRange.findText(str);
        if (strFound) {
            //the following line added by Mike and Susan Keenan, 7 June 2003
            win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
            TRange.select();
            }
    
    
       }
       
       else {
    
         TRange=win.document.body.createTextRange();
         TRange.collapse(false);
         strFound=TRange.findText(str);
         if (strFound) {
            //the following line added by Mike and Susan Keenan, 7 June 2003
            win.document.body.scrollTop = TRange.offsetTop;
            TRange.select();
            }
    
    
    
       }
      }
      
       if (TRange==null || strFound==0) {
       TRange=win.document.body.createTextRange();
       dupeRange = TRange.duplicate();
       strFound=TRange.findText(str);
        if (strFound) {
            //the following line added by Mike and Susan Keenan, 7 June 2003
            win.document.body.scrollTop = TRange.offsetTop;
            TRange.select();
            }
    
       
       }
    
     }
    
      if (!strFound) alert ("String '"+str+"' not found!") // string not found
    
            
    }
    
    </script>
    <div>
    &nbsp;
    </div>
    <!--  EXAMPLE FORM OF FIND-IN-PAGE SEARCH USING SUBMIT (ALLOWING 'ENTER/RETURN' KEY PRESS EVENT) -->
    <div id="lipsum">
      <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porta,   nulla semper volutpat lobortis, orci augue suscipit tortor, id dictum   urna arcu vel ligula. Nullam molestie, urna sit amet gravida vulputate,   justo lacus tristique sapien, ac mollis urna ante eget erat. Ut   vestibulum ipsum ac velit luctus auctor. Nullam sodales vestibulum leo   in vulputate. Aliquam ullamcorper, libero sed auctor ornare, augue   sapien venenatis arcu, ac venenatis odio magna sit amet felis. Praesent   vel neque sed neque commodo pulvinar sed vehicula sem. Nam at malesuada   erat. Nullam eget arcu dui. Maecenas ante nisl, convallis quis luctus   nec, malesuada id tellus. Aliquam nec dolor eget urna lobortis convallis   vitae a mauris. Morbi at urna libero. In hac habitasse platea dictumst.   In vel mauris nisi. </p>
      <p> Duis ac lectus non dolor venenatis tristique sit amet ac magna. In vitae   neque odio, lacinia fermentum nibh. Sed feugiat blandit sem, eu rutrum   nulla molestie ac. Sed pretium tellus at odio congue ultricies. Nulla   aliquam malesuada quam ut porta. Praesent ornare auctor mollis. Cras   interdum scelerisque diam, ut accumsan neque aliquam sit amet. Lorem   ipsum dolor sit amet, consectetur adipiscing elit. Nam sed dui at sapien   euismod porta a a elit. Aenean mattis erat vel nisl dapibus imperdiet.   In fringilla molestie velit, eget posuere mi rutrum vitae. Aliquam   tempus ullamcorper pulvinar. Curabitur ligula quam, tristique at   ultricies id, vestibulum in mi. Duis egestas sagittis justo, in viverra   risus convallis a. </p>
      <p> Curabitur bibendum, massa quis congue pharetra, orci felis pellentesque   mi, in volutpat justo lorem a dolor. Aliquam ut massa mi. Pellentesque   tincidunt ornare vehicula. In rutrum, tortor sit amet imperdiet dapibus,   nulla nulla varius tortor, at rhoncus risus ante vitae eros.   Suspendisse imperdiet tortor turpis. Nulla tristique faucibus felis,   eget eleifend odio pellentesque at. Sed porttitor magna sit amet est   ultrices eget bibendum ipsum commodo. Proin augue mi, ornare quis   pharetra sit amet, commodo in orci. Phasellus quis nulla at nisl blandit   interdum vitae id enim. Vivamus congue rhoncus pharetra. Donec ultrices   sodales felis vitae viverra. Aliquam at nisl erat. Nulla et vestibulum   libero. Ut ac pharetra lectus. </p>
      <p> Etiam semper lectus id sem varius non sagittis metus tincidunt. Proin   aliquam viverra nisi, auctor accumsan nibh gravida in. Etiam ante leo,   vulputate in dapibus nec, molestie sed turpis. Aliquam sollicitudin nunc   rhoncus velit interdum euismod. Ut euismod dui eget ante accumsan a   sagittis ligula bibendum. Duis at ipsum a erat rutrum auctor quis eu   ligula. Vivamus feugiat enim nec mauris feugiat in auctor elit   elementum. Quisque molestie dui vel enim rhoncus a porttitor massa   porta. Morbi nec mauris tortor. Suspendisse hendrerit vulputate massa id   varius. Duis in ipsum ante. Quisque est velit, iaculis pretium commodo   sit amet, pellentesque vel nulla. Integer eu felis eu tellus consectetur   venenatis. Aenean tincidunt ullamcorper tellus, et placerat sapien   tempus quis. Nunc quis metus neque, tempor condimentum odio. </p>
    </div><form style="position: absolute; top: 10px; left: 10px;" name="form1" onSubmit="search(document.form1, frametosearch); return false"><input type="text" name="findthis" size="15" title="Press 'ALT s' after clicking submit to repeatedly search page"> <input type="submit" value="Find in Page" ACCESSKEY="s"></form>
    </body>
    </html>
    No good in Opera yet, and I don't know about mobile devices - nothing to check on. But Chrome and Safari are now good. When I have more time, I'll see about making it more generic and about tightening up the code a bit as well (the above is pretty sloppy looking).
    Last edited by jscheuer1; 05-23-2011 at 01:11 AM. Reason: add detail
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    metall5468 (06-22-2011)

  6. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I figured out why in Firefox there is the limited capability to search sections of the page as described in post #2 of this thread. That was on your page, not the demo page that results if one follows the instructions for installation of the script.

    The difference being that your form is not the last thing before the closing </body> tag. For the entire page to be taken in, it must be. That's why it's absolutely positioned in the demo instructions to appear at the top, while actually being the last thing in the DOM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    metall5468 (06-22-2011)

Bookmarks

Posting Permissions

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