Click to See Complete Forum and Search --> : how do i rewrite something?
Da Warriah
12-27-2002, 06:40 PM
ok, i have a page that i cant "directly access", its a forum that has its own server, kinda like ezboards (only better, of course)...
ok, so how can i write a javascript to replace text with different text?
for example, if i wanted to replace all the "blah"s on the page with "whatever"s, how would i go about doing that?
Da Warriah
12-28-2002, 10:41 AM
ok, i found the answer to my problem, and yes it does work in javascript, you must have misunderstood my question...
var range = document.body.createTextRange();
range.collapse(true);
while (range.findText("original text")) {
range.text="new text";
range.collapse(false);
}
jschweed3
12-28-2002, 12:05 PM
Well, you do what you can, right?
Da Warriah, I didn't know you were a member here...;)
But, about that code - yea, you use it for pages with default templates...But, maybe you need to check for more than one thing to do something else...
Someone asked me if they could check for two things: Welcome Guest, and <<Home>> or whatever...to do one thing. Is there any way to do that? I told him to just use: Hey, : and it should work, but that might not be satisfactory...
Da Warriah
12-28-2002, 01:02 PM
hey jschweed3!! what a weird coincidence, holy cow...
anyways, this should work for your problem:
var range = document.body.createTextRange();
range.collapse(true);
while (range.findText("original text") && range.findText("other original text")) {
range.text="new text";
range.collapse(false);
}
Da Warriah
12-28-2002, 01:26 PM
hmm, i think youre right...but im not quite sure what hes asking...
but i know this will work, i used lots of these on my forums;):
var range = document.body.createTextRange();
range.collapse(true);
while (range.findText("original text")) {
range.text="new text";
range.collapse(false);
}
while (range.findText("other original text")) {
range.text="new text";
range.collapse(false);
}
jschweed3
12-28-2002, 02:11 PM
Yea, that'll work - BUT - it still does two statements, two statements for two outputs...sorry if that isn't clear...This is what he wants to do:
He wanted to use that code, to make a quick login...but, he only wanted it on the first page [main page], and the first page only...So, I told him to just use "Hey," as the original..But, there has to be another way to be able to use two statements, and if they are both true, execute one command...Maybe two variables come into play...I'll think about it
Da Warriah
12-28-2002, 03:47 PM
oh, well in that case, the first code, with a little modification for the outcome, would work:
var range = document.body.createTextRange();
range.collapse(true);
while (range.findText("Welcome Guest") && range.findText("<<Home>>")) {
range.collapse(false);
// blah blah blah, put all your quick login stuff in here
}
jschweed3
12-28-2002, 07:23 PM
Okay, thank you very much DW...If you need any help, I'll at least try :cool: