Email conversation
From | Jean Korte |
To | Me |
Subject | Find in Page Script |
Date | 16 May 2005 01:34 |
Dear Mark
Thanks so much for all the information on your site.
I would like to use your findInPage script on a page containing over 1000
links -
[URL]
I realized, thouigh, that I could not find links that were not visible and
also when a hit scrolls the search box out of view, it is awkward to repeat
the find. So I created a page containing all the links in a sized,
scrollable <div> here;
[URL]
Here is a test page into which I have inserted your script with no
modificaions.
[URL]
Now to my questions.
The script works in Explorer. However, in Firefox and Netscape, the script
searches only the portion of the page occurring before the <div>. I have
tried giving my <div> an id and then using that id as the frameToSearch but
this does not work.
It would be great if I could make the script search only my <div> in both
Firefox and Explorer!!
By the way, in Opera, the form does not display but the alert box advising
the user to use their browser search facility does not appear.
I have no way of testing this with Mac browsers but if I can get it to work
in FF then I can ask someone to test it on a Mac.
Any help or suggestions would be very much appreciated.
Cheers
Jean
From | Me |
To | Jean Korte |
Subject | Re: Find in Page Script |
Date | 16 May 2005 11:27 |
Jean,
> I realized, thouigh, that I could not find links that were not visible
> and also when a hit scrolls the search box out of view, it is awkward to
> repeat the find.
If you put the form in a fixed position DIV it would be a lot easier. Since
then, when the page scrolls, the "find-in-page" form will stay fixed on the
screen, so it can always be reached. Of course, you would need a JavaScript
trick of some kind to make it work in IE ...
> in Firefox and Netscape, the script searches only the portion of the
> page occurring before the <div>.
Urgh. Nice bug. It relates to the fact that each time you click the button,
it changes the current selection. It used to work properly, but I see that
it now has the same problem on my test page. I don't think there is any easy
way to avoid it, although I have two ideas:
1 - put the links in an iframe, and the form in the main page, and make it
search the iframe. This is the easiest and probably the most likely to
succeed. It would also work in reverse, putting the form in an iframe, and
making it search the parent page.
2 - use a shortcut key to submit the form, using JavaScript to detect
keypresses, and if it is the special key ('f', for example), and the search
box is not focused, run the onsubmit method of the form.
I need to find a better solution, but just not sure what to do yet ...
> I have tried giving my <div> an id and then using that id as the
> frameToSearch but this does not work.
It might be possible to do this in IE, since it uses textranges, and these
can be limited to a block of text. In FF this is impossible, since the
script just hooks into the browser's own find function.
> By the way, in Opera, the form does not display but the alert box
> advising the user to use their browser search facility does not appear.
Correct, it will not. The alert will only appear if you allow Opera to see
the form, and they try to use it. It is there as a precaution, in case the
page author does not use my 'if' statement to hide the form in Opera. If you
want to display a message in Opera, put your own 'else' statement after the
'if':
if( ( document.body && document.body.createTextRange ) || window.find ) {
...
} else {
document.write('<p>Please use your browser's search</p>');
}
> I have no way of testing this with Mac browsers but if I can get it to
> work in FF then I can ask someone to test it on a Mac.
Apart from Mozilla/Firefox/Camino/other Geckos, it will only work on the
more obscure iCab and OmniWeb 4.2-. It will not work in IE Mac, Safari,
OmniWeb 4.5+, or Opera on Mac.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/