Results 1 to 7 of 7

Thread: (Javascript) What is the equivilent to ASP's inStr in javascript?

  1. #1

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057

    (Javascript) What is the equivilent to ASP's inStr in javascript?

    I know I have asked this before but I cannot find the post or where I used it in my code so....

    What is the equivilent to ASP's inStr in javascript?

    thanks
    Michael
    I'm off to GalahTech, hope to see you there.

    If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Code:
    function InstrThing(str,substr,start){
        var oStr = new String(str);
        return oStr.indexOf(substr,start);
    }
    indexOf returns position of substring in string or -1 if not found

  3. #3

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    Thanks.
    I am trying to make a javascript redirect depening on IE version. I want it to go one way if 5.5+ and another way if 5.0- Here is what I have so far:
    Code:
    document.write(navigator.appVersion + '<br><br>');
    var intStart = (navigator.appVersion.indexOf('MSIE',1) + 5);
    var intVers = navigator.appVersion.substring(parseInt(intStart), 3);
    document.write(intStart + '<br>');
    document.write(intVers);
    and the output:
    4.0 (compatible; MSIE 5.5; Windows NT 4.0; T312461)

    22
    (compatible; MSIE
    so it is starting at the fourth position and giving me the next 22 chars... i want it to start at the 22position and give me the next 3 chars... so I flip it and it does the same...
    and ideas?
    Michael
    Last edited by msimmons; Oct 9th, 2002 at 02:25 PM.
    I'm off to GalahTech, hope to see you there.

    If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    ahh if it's browser version you want
    have a look at this

  5. #5

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    The problem with that script (besides being too dang long ) is that is only detects ie4+ or ie3- i need ie5.5+ ie ie5.0-
    Michael
    I'm off to GalahTech, hope to see you there.

    If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.

  6. #6

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    k here is what i did

    Code:
     var browserName = navigator.appName;
    	if (browserName == "Microsoft Internet Explorer"){
    		if (navigator.appVersion.indexOf('MSIE 5.5',1)!=-1 || navigator.appVersion.indexOf('MSIE 6.0',1)!=-1){
    			alert('ok go to net');
    		}else{
    			alert('get a new browser');
    		}
    	}
    I know that is bad cos it only covers IE and will fail on the next vers of IE but this is only temporary

    thanks
    Michael
    I'm off to GalahTech, hope to see you there.

    If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.

  7. #7
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Code:
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    
    var fullVersion = parseFloat(nVer);
    var majorVersion = parseInt(nVer);
    
    // In Internet Explorer, the true version is after "MSIE" 
    
    if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
     fullVersion = parseFloat(nAgt.substring(verOffset+5,nAgt.length));
     majorVersion = parseInt(''+fullVersion);
    }
    
    // In Opera, the true version is after "Opera"
    
    if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
     fullVersion = parseFloat(nAgt.substring(verOffset+6,nAgt.length));
     majorVersion = parseInt(''+fullVersion);
    }
    
    document.write('Full version = '+fullVersion+'<br>');
    document.write('Major version = '+majorVersion);
    ok that link was me being lazy this will give you the version number.

Posting Permissions

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



Click Here to Expand Forum to Full Width