Javascript problem

Discussion in 'Computer Information' started by Robert Baer, Apr 14, 2014.

  1. Robert Baer

    Robert Baer Guest

    Need a different pair of eyes on this, methinks.


    <script>
    function FindJump(gogo)
    {
    gogo='';
    str=navigator.userAgent; // Agent is unique for our purposes
    /* lotza working code edited out */
    var isGek=str.indexOf("Gecko"); // Presumes is in all variants mentioned
    if (isGek>=0) { gogo='PCbase.html'; }
    var z = gogo;

    // So, if not found, ASSuME we have mobile phone browser
    if (z='') { gogo='Mobile.html'; }
    document.writeln('3 gogo='+gogo+'|<BR>');
    document.writeln('4 z='+z+'|<BR>');
    return 'foo'+z+'||' //gogo;
    };
    </script>

    <script>
    str=navigator.userAgent; // Agent is unique for our purposes
    document.writeln(str+"|<BR>");
    // <a onTimeout="doOut(this, '/'+str', 'sass');return false;"></a><br>
    var jmp=FindJump("hi");
    document.writeln('jmp='+jmp);
    </script>

    /* on a PC, one sees: /* on a mobile phone, one sees:
    3 gogo=PCbase.html| jmp=Mobile.html|
    4 z=|
    jmp=foo||

    */

    For a mobile phone:
    1) What is seen is reasonable, as contents of "str" had been previously
    detected and the proper string was returned earlier in the function.

    For a PC:
    1) Line 3 shows that "z" was not empty; if it was, then "gogo"
    would contain 'Mobile.html'
    2) But line 4 then shows "z" as empty. WTF?
    3) Likewise,the next line shows "z" as empty.
     
    Robert Baer, Apr 14, 2014
    #1
    1. Advertisements

  2. Robert Baer

    Paul Guest

    if (z=='')...

    Equivalence testing is described here. There's the same problem
    in C, where I occasionally type one "=" instead of two, when
    doing an equivalence check.

    http://javascript.about.com/od/decisionmaking/a/des02.htm

    Your single "=", is an assignment statement.

    Initially, I thought it might be a variable scoping problem,
    until I caught that one.

    Paul
     
    Paul, Apr 14, 2014
    #2
    1. Advertisements

  3. Robert Baer

    Robert Baer Guest

    Thanks!
    I also see that an "extra" equals sign forces a type match as well;
    not only for == but also for != .
     
    Robert Baer, Apr 14, 2014
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.