This is a discussion on "Detecting characters between < and > ?" within the JavaScript Forum section. This forum, and the thread "Detecting characters between < and > ? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Detecting characters between < and > ?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Detecting characters between < and > ?
I'm trying to create/modify a script that highlights certain words on a page, and changes them into links. So if I had a page about dogs, each occurrence of the word 'dog' will be automatically turned into a link.
So far I've got it working, but it's overwriting any links that are already hard coded into the page. I need the script to ignore anything inside < >, such as links, bold, etc... Any ideas?
|
|
|
|
||||
|
Re: Detecting characters between < and > ?
You're going to have to use javascript regex to acheive this...
That's a pretty rough regex... not sure if it will work, I'm not far from bed it's 1 am :S.. This will be the only way you will get the replacing to happen without runing hardcoded links
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: Detecting characters between < and > ?
Why not just hard-code the links?
I use code templates in my editor (old version of HomeSite) to convert words into links. So you type "dogs", press "Ctrl-J", and the link is made. This is more accessible too (links exist without javascript). |
|
|||
|
Re: Detecting characters between < and > ?
Thanks Rakuli, I don't know if you made a typo in there somewhere, but it doesn't work. I replaced my doHighlight function with yours, and none of the 'dog' words where turned into links.
@MikeHopley - I'm trying to create a script that I can drop into pages that will automatically create links depending on what people have searched for. If people hit my site looking for dogs, they get dog links - or cat links if they're searching for cats. EDIT: I've just noticed that webforumz is running Kontera ads - this is basically what I'm trying to create. A script that will search the page for specific words, turn them into links, BUT will also leave any pre existing links alone. Last edited by Kerosene; Jan 4th, 2008 at 22:09. |
|
|||
|
Re: Detecting characters between < and > ?
Okay, that makes sense now. That's a good reason for scripting this.
|
|
|||
|
Re: Detecting characters between < and > ?
I had a go at this, the best I could do using RegExp was to replace all instances of the search term except if it was immediately followed by a '<'.
The following code seems to work okay, but I don't have much experience with javascript/coding in general, so its probably not a very efficient way of doing it. Hopefully someone will post a better solution or point out any improvements that could be made to this code.
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| wrapper not detecting content | saltedm8 | Web Page Design | 4 | Apr 6th, 2008 22:31 |
| Read First 3 characters and last 4 characters of string | JustinStudios | PHP Forum | 2 | Apr 4th, 2008 00:01 |
| Detecting form navigation | amits | JavaScript Forum | 4 | Aug 24th, 2007 16:26 |
| Detecting JRE version using javascript | Nagendra | JavaScript Forum | 0 | Sep 18th, 2006 05:08 |
| Detecting Flash | skuff | Flash & Multimedia Forum | 2 | Aug 19th, 2003 08:38 |