Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How do you search for a text sting in javascript?

How do you search for a text sting in javascript?
Thread Tools
moonmonkey
Professional Poster
Join Date: Jan 2001
Location: Australia
Status: Offline
Reply With Quote
Apr 2, 2006, 07:19 AM
 
I'm having a big problem, I want to make a function that seaches the body of the page, if a certain text string ie "monkey" is present then it activates another function.

I have been trying to use the SearchRange function detailed here, but with no luck!!
http://msconline.maconstate.edu/tuto...dhtml12-08.htm


Please can someone help!

Cheers,

Moonmonkey.
     
registered_user
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Apr 2, 2006, 07:30 AM
 
allyourtext.indexOf('monkey')
     
moonmonkey  (op)
Professional Poster
Join Date: Jan 2001
Location: Australia
Status: Offline
Reply With Quote
Apr 2, 2006, 08:09 AM
 
Originally Posted by registered_user
allyourtext.indexOf('monkey')
OK this works, thanks!
Any idea how I get all the text in the body of the page into the variable?
( Last edited by moonmonkey; Apr 2, 2006 at 08:35 AM. )
     
registered_user
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Apr 2, 2006, 12:58 PM
 
var allyourtext = document.body.innerHTML

oughtta do it.

or .innerText

they're both pretty hackish, but they both oughtta work.
     
madmacgames
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Apr 4, 2006, 12:40 PM
 
innerHTML is kind of "hackish" if you go by the guise that it is not part of EMCA Script or DOM, but was [originally] just an IE thing. But now, pretty much all browsers support innerHTML because it's just so darn handy, so I'm not sure you can really call it "hackish" anymore, even though it is not officially part of EMCA Script or DOM, unofficial, it certainly is.
The only thing necessary for evil to flourish is for good men to do nothing
- Edmund Burke
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:39 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,