Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find a text string on a web page in Safari

Status
Not open for further replies.

JohnACalder

Programmer
Nov 26, 2007
2
US
When the page is loaded I have a function that runs on the OnLoad event. This function searches for a specific text string. WHen it finds the string it highlights the string.
I can do this in IE using createTextRange. I can do it in Firefox using x.find(str...), but both fail in Safari (both Panther and Leopard).
Can any one point me at some good documentation for this?
 
John, I dont think there is a direct equivalent however you should be able to emulate this by using window.getSelection which will work in Safari

Nick
 
Well...I'm new to this but I think getSelection returns the user selection. In my case I need a function to: 1) locate the string, 2) highlight it, and 3) scroll the page (if necessary) so that the string is in the viewing portion of the window without any user intervention.
I can use indexOf() to find the string on the page but I can't figure out how to hightlight (I suppose I could wrap the string with some tags to highlight it, but I'm still left with the scrolling part. Any ideas?
Thanks,
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top