Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-31-2010, 10:53 PM   PM User | #1
JimNayzium
New Coder

 
Join Date: Nov 2007
Posts: 46
Thanks: 4
Thanked 0 Times in 0 Posts
JimNayzium is an unknown quantity at this point
String search won't find "> >" for some reason

Here is the link in question.
I have created a small page with the isolated problem on it.

http://frontendaudio.com/v/vspfiles/...pt_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.

Code:
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;
JimNayzium is offline   Reply With Quote
Old 08-31-2010, 11:02 PM   PM User | #2
codebyter
New Coder

 
Join Date: Aug 2010
Location: FL
Posts: 35
Thanks: 0
Thanked 1 Time in 1 Post
codebyter is an unknown quantity at this point
try using indexOf. it will return the position of the first occurence or false of it doesnt exist
codebyter is offline   Reply With Quote
Old 08-31-2010, 11:05 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Did you think to do
Code:
	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;"
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
JimNayzium (09-01-2010)
Old 08-31-2010, 11:07 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by codebyter View Post
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 08-31-2010, 11:08 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 08-31-2010, 11:52 PM   PM User | #6
codebyter
New Coder

 
Join Date: Aug 2010
Location: FL
Posts: 35
Thanks: 0
Thanked 1 Time in 1 Post
codebyter is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
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 is offline   Reply With Quote
Old 08-31-2010, 11:54 PM   PM User | #7
codebyter
New Coder

 
Join Date: Aug 2010
Location: FL
Posts: 35
Thanks: 0
Thanked 1 Time in 1 Post
codebyter is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Did you think to do
Code:
	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() ?
codebyter is offline   Reply With Quote
Old 08-31-2010, 11:57 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Sure, but why???

Instead, actually search for that.
Code:
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 09-01-2010, 05:28 PM   PM User | #9
JimNayzium
New Coder

 
Join Date: Nov 2007
Posts: 46
Thanks: 4
Thanked 0 Times in 0 Posts
JimNayzium is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Did you think to do
Code:
	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.
JimNayzium is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:48 AM.


Advertisement
Log in to turn off these ads.