javascript parameter isn't passing

Discussion in 'Javascript' started by Mary Kline, May 31, 2009.

  1. Mary Kline

    Mary Kline Guest

    hi,

    why the parameter cno isn't passing? What wrong in this?
    <script type="text/javascript">
    function test(cno)
    {
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
    if (browser=="Netscape")
    {
    document.write('<strong>Supported Browsers :<\/strong> IE only.');
    }
    if (browser=="Microsoft Internet Explorer")
    {
    document.write('<script type="text/javascript" src="http://
    dl.tvunetworks.com/webplayer/myTVU.js?c="+cno
    +"&amp;w=550&amp;h=385&amp;autoplay=1&amp;style=0"><\/script>');
    }
    }
    test(1111);
    </script>


    Any help appreciated.

    TIA
    -Mary
     
    Mary Kline, May 31, 2009
    #1
    1. Advertising

  2. Mary Kline

    Eric Bednarz Guest

    Mary Kline <> writes:

    > why the parameter cno isn't passing?


    Because you don’t use it. You just write ‘cno’ as part of a longer
    string.

    > What wrong in this?


    > var browser=navigator.appName;


    That, for starters.

    This probably answers why you want to use document.write to insert the
    script element in the first place. Instead of user agent sniffing you
    should use conditional comments, e.g.

    <!--[if IE]>
    <script type="text/javascript" src="[…]"></script>
    <![endif]–>

    Cf. <http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx>

    Another question would be why you want to make that IE-only in the first
    place.
     
    Eric Bednarz, May 31, 2009
    #2
    1. Advertising

  3. Mary Kline

    kouPhax Guest

    On May 31, 10:19 pm, Eric Bednarz <> wrote:

    > <!--[if IE]>
    > <script type="text/javascript" src="[…]"></script>
    > <![endif]–>


    Assuming the OP's code above is the actual script she intends to use
    then script "written" onto the page has a dynamic URL (built seemingly
    from user input - and passed as the argument to the function).
    Conditional comments wouldn't actually work in this case.

    > Another question would be why you want to make that IE-only in the first
    > place.


    This is the question that needs answered first I think.

    James.
     
    kouPhax, Jun 1, 2009
    #3
  4. Mary Kline wrote:
    > why the parameter cno isn't passing? What wrong in this?
    > <script type="text/javascript">
    > function test(cno)
    > {
    > var browser=navigator.appName;
    > var b_version=navigator.appVersion;
    > var version=parseFloat(b_version);

    ^^^^^^^
    Unused variable.

    > if (browser=="Netscape")
    > {
    > document.write('<strong>Supported Browsers :<\/strong> IE only.');
    > }
    > if (browser=="Microsoft Internet Explorer")
    > {
    > document.write('<script type="text/javascript" src="http://
    > dl.tvunetworks.com/webplayer/myTVU.js?c="+cno
    > +"&amp;w=550&amp;h=385&amp;autoplay=1&amp;style=0"><\/script>');
    > }
    > }
    > test(1111);
    > </script>


    Provided there is no script error¹, I see two distinct possibilities:

    A) You are using a browser for which

    navigator.appName == "Microsoft Internet Explorer"

    does not apply. Possibility: Mozilla Firefox.

    See also <http://PointedEars.de/scripts/test/whatami>.

    B) You are redeclaring test() below. Variable instantiation
    takes place before execution.


    HTH

    PointedEars
    ___________
    ¹ <http://www.jibbering.com/faq/#javascriptErrors>
     
    Thomas 'PointedEars' Lahn, Jun 1, 2009
    #4
  5. Mary Kline wrote:
    > hi,
    >
    > why the parameter cno isn't passing? What wrong in this?


    [...]

    I suggest getting rid of that code. Whatever it is intended to do, it is
    badly designed. This is evidenced by a question Eric Bednarz raised.

    >
    >
    > Any help appreciated.
    >


    Learn to ask a smart question. Particularly about describing the goal,
    not why the reckless strategy (with unused variables) in the code posted
    fails[1].

    Read the FAQ section on posting[2].

    Also see the FAQ notes on browser detection and what to do instead[3].

    [1]http://catb.org/esr/faqs/smart-questions.html#goal
    [2]http://jibbering.com/faq/#posting
    [3]http://jibbering.com/faq/faq_notes/not_browser_detect.html#bdTop

    Garrett
     
    Garrett Smith, Jun 1, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alf
    Replies:
    2
    Views:
    17,897
    azoozey
    Apr 1, 2011
  2. Bishoy George
    Replies:
    8
    Views:
    10,883
    Bishoy George
    Sep 28, 2005
  3. Werner Rudolf
    Replies:
    2
    Views:
    3,078
    Werner Rudolf
    Apr 15, 2005
  4. Rafe
    Replies:
    5
    Views:
    287
    Wolfgang Grafen
    Aug 15, 2008
  5. Mister B
    Replies:
    8
    Views:
    554
    Nick Keighley
    Aug 26, 2010
Loading...

Share This Page