HighDots Forums  

Javascript code working with Firefox but not with IE... need help!

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Javascript code working with Firefox but not with IE... need help! in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John Ca
 
Posts: n/a

Default Javascript code working with Firefox but not with IE... need help! - 10-04-2009 , 06:38 PM






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!

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 the script itself:

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

}
}

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.