J
John Ca
Hi Everyone!
I'm posting this as a follow up message on my previously started
thread here:
http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/63fff03661714519?hl=en
Unfortunately since that thread went quite a bit off-topic, I'm
starting this new thread instead!
Anyway, I'm experiencing a very strange problem with IE6... in my
original post I was trying to figure out how to build a function which
will work both with IE & FF, the purpose of which is to highlight
certain keywords in the page's paragraphs, and turn them into
hyperlinks!
RobG was gracious enough to provide me with a working function which
achieves just that, and works both with IE and FF (the function I was
using before that worked only in FF).
Here is the function provided by RobG:
function create_links() {
var keywords = ['Keyword1','Keyword2','Keyword3','Keyword4'],
p,
pCollection = document.getElementsByTagName("p"),
re,
word;
for (var i=0, iLen=pCollection.length; i<iLen; i++) {
p = pCollection;
for (var j=0, jLen=keywords.length; j<jLen; j++) {
word = keywords[j];
re = new RegExp('\\b' + word + '\\b','g');
p.innerHTML = p.innerHTML.replace(re,
'<a href="http://www.mysite.com">' + word + '</a>');
}
}
}
As expected the function now works perfectly in both IE & FF, however
there is now a new and very strange problem!!!
Whenever the function executes in IE, it also adds some kind of weird
line breaks just after each paragraph that it modifies... creating
about 2 lines worth of blank space between that paragraph and the next
element on the page!!! For the life of me I cannot figure out what can
possibly be causing this...
Unfortunately since IE6 doesn't have the option of dynamically showing
the page source (unlike FF which has the option to "View selection
source"), I don't really know what it's adding after the <p> elements
specifically! When I select those "empty lines" on the page it's like
there's an empty character (" ") there, and when I copy-paste it into
notepad it goes down one line, so I assume it's a line-break
character.
Also, since I only have IE6 installed on my machine, I didn't have a
chance to test it with IE7, so I don't know if it applies to all
versions of IE or just IE6, but nonetheless it's extremely strange!
If anyone has any ideas as to what might be causing this, and how to
fix this I would greatly appreciate your help!!!
I'm calling the function in an "onload" event in the body tag as such:
<body onload="create_links();">
If I left out any important information please let me know!
Thanks,
John
I'm posting this as a follow up message on my previously started
thread here:
http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/63fff03661714519?hl=en
Unfortunately since that thread went quite a bit off-topic, I'm
starting this new thread instead!
Anyway, I'm experiencing a very strange problem with IE6... in my
original post I was trying to figure out how to build a function which
will work both with IE & FF, the purpose of which is to highlight
certain keywords in the page's paragraphs, and turn them into
hyperlinks!
RobG was gracious enough to provide me with a working function which
achieves just that, and works both with IE and FF (the function I was
using before that worked only in FF).
Here is the function provided by RobG:
function create_links() {
var keywords = ['Keyword1','Keyword2','Keyword3','Keyword4'],
p,
pCollection = document.getElementsByTagName("p"),
re,
word;
for (var i=0, iLen=pCollection.length; i<iLen; i++) {
p = pCollection;
for (var j=0, jLen=keywords.length; j<jLen; j++) {
word = keywords[j];
re = new RegExp('\\b' + word + '\\b','g');
p.innerHTML = p.innerHTML.replace(re,
'<a href="http://www.mysite.com">' + word + '</a>');
}
}
}
As expected the function now works perfectly in both IE & FF, however
there is now a new and very strange problem!!!
Whenever the function executes in IE, it also adds some kind of weird
line breaks just after each paragraph that it modifies... creating
about 2 lines worth of blank space between that paragraph and the next
element on the page!!! For the life of me I cannot figure out what can
possibly be causing this...
Unfortunately since IE6 doesn't have the option of dynamically showing
the page source (unlike FF which has the option to "View selection
source"), I don't really know what it's adding after the <p> elements
specifically! When I select those "empty lines" on the page it's like
there's an empty character (" ") there, and when I copy-paste it into
notepad it goes down one line, so I assume it's a line-break
character.
Also, since I only have IE6 installed on my machine, I didn't have a
chance to test it with IE7, so I don't know if it applies to all
versions of IE or just IE6, but nonetheless it's extremely strange!
If anyone has any ideas as to what might be causing this, and how to
fix this I would greatly appreciate your help!!!
I'm calling the function in an "onload" event in the body tag as such:
<body onload="create_links();">
If I left out any important information please let me know!
Thanks,
John