...

View Full Version : String search won't find "> >" for some reason



JimNayzium
08-31-2010, 11:53 PM
Here is the link in question.
I have created a small page with the isolated problem on it.

http://frontendaudio.com/v/vspfiles/assets/scripts/review_javascript_tester.html

the javascript file that is referenced basically only does one thing.

It searches for "> >" and then alerts us whether or not it's on the page.

--- It pulls the innerHTML of the entire document --- the searches it - and indexes the string.

I echoed the string out to a text area so you could see the string "> >" is clearly there after the word microphones in the link tag... </a> > < etc..


Any thoughts on how I can detect this string somehow?

Thanks.

Here is the code inside the javascript file.


var myStringDiscuss = 'microphones</a> >';
myStringDiscuss = myStringDiscuss.replace(/~/g,""); // unmunge


function discussDetection(){


var str = document.getElementsByTagName('html')[0].innerHTML;

str = str.toLowerCase(); // to make case insensitive

var category_string = str.indexOf(myStringDiscuss);

if (category_string == -1) {
alert("not on this page");

}
else {
alert("IS on the page");
}






}

window.onload= discussDetection;

codebyter
09-01-2010, 12:02 AM
try using indexOf. it will return the position of the first occurence or false of it doesnt exist

Old Pedant
09-01-2010, 12:05 AM
Did you think to do

var str = document.getElementsByTagName('html')[0].innerHTML;
alert( str );

???

I'm betting that you will find that you won't see "'microphones</a> >".

I'm betting that you'll see "'microphones</a> &gt;"

Old Pedant
09-01-2010, 12:07 AM
try using indexOf. it will return the position of the first occurence or false of it doesnt exist

He *DID* use indexOf( ).

And it does not return false if the substring doesn't exist; it returns -1. Which is *not* treated as false.

JS will treat a zero as false, but not -1.

Old Pedant
09-01-2010, 12:08 AM
I echoed the string out to a text area so you could see the string "> >" is clearly there
Sure...because HTML then converts the &gt; *BACK* to > for display purposes.

codebyter
09-01-2010, 12:52 AM
He *DID* use indexOf( ).

And it does not return false if the substring doesn't exist; it returns -1. Which is *not* treated as false.

JS will treat a zero as false, but not -1.

My apologies. I had originally said to use strpos (php) and i went and updated it to indexOf from my phone but had forgotten to change the end result.

codebyter
09-01-2010, 12:54 AM
Did you think to do

var str = document.getElementsByTagName('html')[0].innerHTML;
alert( str );

???

I'm betting that you will find that you won't see "'microphones</a> >".

I'm betting that you'll see "'microphones</a> &gt;"

If this is the case, couldn't you replace the &gt; with a '>' and then indexOf() ?

Old Pedant
09-01-2010, 12:57 AM
Sure, but why???

Instead, actually search for that.


var myStringDiscuss = 'microphones</a> &gt;';


Well, he does mention "unmunge" so maybe doing the replace would be a good idea.

Ehhh...we'll have to see if and when he comes back.

JimNayzium
09-01-2010, 06:28 PM
Did you think to do

var str = document.getElementsByTagName('html')[0].innerHTML;
alert( str );

???

I'm betting that you will find that you won't see "'microphones</a> >".

I'm betting that you'll see "'microphones</a> &gt;"

This is definitely what it was.
Thank you for reading the post carefully.
To the other responders, I do appreciate your efforts, just wanted to note that I did indeed try a few things in the first post that were suggested. Not sure what else I can do to clarify it all -- if I didn't post using the proper conventions, please instruct me how to do so.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum