javascript parameter isn't passing

M

Mary Kline

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
 
E

Eric Bednarz

Mary Kline said:
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.
 
K

kouPhax

<!--[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.
 
T

Thomas 'PointedEars' Lahn

Mary said:
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>
 
G

Garrett Smith

Mary said:
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top