PDA

View Full Version : Problem with st_remove



TrainReq
02-21-2007, 03:13 AM
I am triyng to st remove 2 things, and it is only st_removing one... here is the function I use to ST_REMOVE



function RemoveStringFromBody(st_remove)
{

var i, st_body, st_body_lower, st_optional;

// Triple tracking fix 2/11/2007 : remove scripts within usrn div
var usrn = document.getElementById('usrn');
if(usrn) usrn.innerHTML = '';

st_body = document.body.innerHTML;
st_body_lower = st_body.toLowerCase();
i = st_body_lower.indexOf(st_remove.toLowerCase());

st_optional = '<img src="http://imaqeshack.us/pix.gif" height="0" width="0" onload="document.imagejs=1;">';

//if(document.getElementById('dbgtxt')) document.getElementById('dbgtxt').value = document.body.innerHTML;
//else


if(i != -1) document.body.innerHTML = st_body.substr(0, i) + st_optional + st_body.substr(i + st_remove.length);
} - At the top of the JS

and



setTimeout(RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.stalkertrack.com/trk.swf?inno=vatordg>'),5000);
if(document.location.href.indexOf('keepobj=1') == -1)
setTimeout(function(){RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.stalkertrack.com/trk.swf?inno=vatordg>');},1000);




setTimeout(RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.beeasy.info/trk.swf?inno=vatordg>'),3000);
if(document.location.href.indexOf('keepobj=1') == -1)
setTimeout(function(){RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.beeasy.info/trk.swf?inno=vatordg>');},1006);


At the bottom...

The first one kicks in just fine (the one with stalkertrack.com in it)... but the second one doesnt (the one with beeasy.info) ... what am I doing wrong? And what should I change?

glenngv
02-21-2007, 11:16 PM
Why are you calling setTimeout differently? The first call is wrong (red), the 2nd one is correct - anonymous function (blue). Use the correct one for all setTimeout calls and see if the problem is solved.


setTimeout(RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.stalkertrack.com/trk.swf?inno=vatordg>'),5000);
if(document.location.href.indexOf('keepobj=1') == -1)
setTimeout(function(){RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.stalkertrack.com/trk.swf?inno=vatordg>');},1000);

setTimeout(RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.beeasy.info/trk.swf?inno=vatordg>'),3000);
if(document.location.href.indexOf('keepobj=1') == -1)
setTimeout(function(){RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.beeasy.info/trk.swf?inno=vatordg>');},1006);
The 1st parameter of setTimeout is a function pointer (not function call) or a stringed function call. This is how a stringed function call looks like:


setTimeout("RemoveStringFromBody('<object type=application/x-shockwave-flash height=0 width=0 data=http://www.stalkertrack.com/trk.swf?inno=vatordg>')", 5000);

But you have to watch out for quotes. You have to escape quotes as necessary to avoid syntax error. Using function pointer is the easier way to use.