|
|
How do you search for a text sting in javascript?
|
|
|
|
Professional Poster
Join Date: Jan 2001
Location: Australia
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status:
Offline
|
|
allyourtext.indexOf('monkey')
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Jan 2001
Location: Australia
Status:
Offline
|
|
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.
)
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status:
Offline
|
|
var allyourtext = document.body.innerHTML
oughtta do it.
or .innerText
they're both pretty hackish, but they both oughtta work.
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Oct 2003
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|