J
John Ca
Hi all!
I'm a javascript newbie, and I wrote a function who's purpose is to
scan all paragraphs in a page, and then highlight certain keywords
which I provide in advance and turn them into hyperlinks! Simple
enough!
The problem is that the function works perfectly with Firefox (I am
using latest version 3.5.3), but with Internet Explorer it does not
work. I have tested it both with IE6 & IE7, and they both give me a
javascript error and the script doesn't do anything.
Since I am a total newbie when it comes to javascript I have
absolutely no idea what the problem could be, especially since the
script works as intended in Firefox! I would appreciate any help
anyone could provide...
I am calling the script function with an 'onload' event in the <body>
tag!
Here is my script:
function create_links() {
var KeywordsArray = new Array
("Keyword1","Keyword2","Keyword3","Keyword4")
var DocTextArray = document.getElementsByTagName("p")
for (y in DocTextArray) {
var DocText = document.getElementsByTagName("p")[y]
var DocTextContent = DocText.innerHTML
var DocTextNewContent
for (x in KeywordsArray)
{
var NewRegExp = new RegExp(KeywordsArray[x], "g");
DocTextContent = DocTextContent.replace(NewRegExp,"<a
href=\"http://www.mysite.com\">" + KeywordsArray[x] + "</a>")
}
DocText.innerHTML = DocTextContent
}
}
Thanks in advance to anyone willing to help out!!!
John
I'm a javascript newbie, and I wrote a function who's purpose is to
scan all paragraphs in a page, and then highlight certain keywords
which I provide in advance and turn them into hyperlinks! Simple
enough!
The problem is that the function works perfectly with Firefox (I am
using latest version 3.5.3), but with Internet Explorer it does not
work. I have tested it both with IE6 & IE7, and they both give me a
javascript error and the script doesn't do anything.
Since I am a total newbie when it comes to javascript I have
absolutely no idea what the problem could be, especially since the
script works as intended in Firefox! I would appreciate any help
anyone could provide...
I am calling the script function with an 'onload' event in the <body>
tag!
Here is my script:
function create_links() {
var KeywordsArray = new Array
("Keyword1","Keyword2","Keyword3","Keyword4")
var DocTextArray = document.getElementsByTagName("p")
for (y in DocTextArray) {
var DocText = document.getElementsByTagName("p")[y]
var DocTextContent = DocText.innerHTML
var DocTextNewContent
for (x in KeywordsArray)
{
var NewRegExp = new RegExp(KeywordsArray[x], "g");
DocTextContent = DocTextContent.replace(NewRegExp,"<a
href=\"http://www.mysite.com\">" + KeywordsArray[x] + "</a>")
}
DocText.innerHTML = DocTextContent
}
}
Thanks in advance to anyone willing to help out!!!
John