Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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;

  • #2
    New Coder
    Join Date
    Aug 2010
    Location
    FL
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post
    try using indexOf. it will return the position of the first occurence or false of it doesnt exist

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    JimNayzium (09-01-2010)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    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.

  • #6
    New Coder
    Join Date
    Aug 2010
    Location
    FL
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #7
    New Coder
    Join Date
    Aug 2010
    Location
    FL
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post
    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() ?

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    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.

  • #9
    New Coder
    Join Date
    Nov 2007
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •