Click to See Complete Forum and Search --> : Javascript qestion, document.body.createTextRange() in Firefox?
sciguyryan
11-02-2004, 03:02 PM
Hi all,
Can anyone convert this code to make it Firefox compatible?
<script type="text/javascript">
<!--
function Change(I, I1) {
var Range = document.body.createTextRange();
Range.collapse(true);
if (location.href.indexOf("action=") != -1){
return false;
}
else{
while (Range.findText(I)){
Range.text = I1;
Range.collapse(false);
}
}
}
//-->
</script>
Thanks for the help,
RyanJ
There is no equivalent to createTextNode in Mozilla Firefox.
sciguyryan
11-02-2004, 03:14 PM
Originally posted by Jona
There is no equivalent to createTextNode in Mozilla Firefox.
Ok, cheers Jona :)
RyanJ
Originally posted by sciguyryan
Ok, cheers Jona :)
Unless someone (such as Charles) can correct me. ;)
Google for setSelectionRange, undocumented, but will work
7stud
11-02-2004, 05:08 PM
The key is that findText() method for the Range in IE, and I don't think Moz has anything comparable. setSelectionRange() won't do it alone--that's equivalent to createTextRange().
By the way, in your function there is no reason to create a TextRange if you are going to return from the function:
function Change(I, I1)
{
if (location.href.indexOf("action=") != -1) return false;
var Range = document.body.createTextRange();
Range.collapse(true);
while (Range.findText(I))
{
Range.text = I1;
Range.collapse(false);
}
}
Great function. :)
sciguyryan
11-02-2004, 05:38 PM
Originally posted by 7stud
The key is that findText() method for the Range in IE, and I don't think Moz has anything comparable. setSelectionRange() won't do it alone--that's equivalent to createTextRange().
By the way, in your function there is no reason to create a TextRange if you are going to return from the function:
Actually I do.
The script was written for a forum (IF) and the indexOf line checks that a users is on the board and that the ACP is not affected.
The rest finds the text and then changes it.
RyanJ
7stud
11-02-2004, 09:13 PM
What exactly do you want the function to do? Can you describe how the function is used?
sciguyryan
11-03-2004, 11:00 AM
Ok,
It checks the local URL for action= (Anshures in the forums)
Next, it finds the first perameter and then replaces that with the second one.
Thats it.
RyanJ
7stud
11-03-2004, 11:59 AM
It checks the local URL for action= (Anshures in the forums)
Next, it finds the first perameter and then replaces that with the second one.
Yes, I read the code. Good luck!