Forum Moderators: open

Message Too Old, No Replies

i dont know whats wrong with this browser detect script

it says something like "unterminated string constant"

         

mylungsarempty

8:46 am on Mar 31, 2004 (gmt 0)

10+ Year Member



<script language="Javascript">

function getBrowser() {
var vBrowser=navigator.appName;
var vFade;

if (vBrowser.indexOf("Netscape")>=0)
{vFade='omitted for purposes of brevity';}
else if (vBrowser.indexOf("Microsoft")>=0)
{vFade='omitted for purposes of brevity';}

else

{vFade='omitted for purposes of brevity';}
return(vFade);
}
</script>

Zaphod Beeblebrox

9:44 am on Mar 31, 2004 (gmt 0)

10+ Year Member



It seems there might be an extra quote somewhere in the strings you omitted. Maybe you can post them?

RonPK

9:49 am on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, a quote or else a line break within one of the strings.

Rambo Tribble

3:00 pm on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try using: !=-1 for your conditional rather than >=.

mylungsarempty

4:29 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



<script language="Javascript">

function getBrowser() {
var vBrowser=navigator.appName;
var vFade;

if (vBrowser.indexOf("Netscape")>=0)
{vFade='<DIV style="position: absolute\; left: 165px\; top: 142px\; z-index:4\;">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)\;" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</DIV>
<DIV style="position: absolute\; left: 475px\; top: 142px\; z-index:4\;">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)\;" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</DIV>
<DIV style="position: absolute\; left: 165px\; top: 436px\; z-index:4\;">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)\;" src="/images/frame_bottom.png" width="280" height="8" border="0" alt="">
</DIV>
<DIV style="position: absolute\; left: 475px\; top: 436px\; z-index:4\;">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)\;" src="/images/frame_bottom.png" width="280" height="8" border="0" alt="">
</DIV>';}
else if (vBrowser.indexOf("Microsoft")>=0)
{vFade='<DIV style="position: absolute; left: 165px; top: 142px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_top.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</span>
</DIV>

<DIV style="position: absolute; left: 475px; top: 142px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_top.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</span>
</DIV>

<DIV style="position: absolute; left: 165px; top: 436px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_bottom.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_bottom.png" width="280" height="8" border="0" alt="">
</span>
</DIV>

<DIV style="position: absolute; left: 475px; top: 436px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_bottom.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_bottom.png" width="280" height="8" border="0" alt="">
</span>
</DIV>';}

else

{vFade='<DIV style="position: absolute; left: 165px; top: 142px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_top.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</span>
</DIV>

<DIV style="position: absolute; left: 475px; top: 142px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_top.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</span>
</DIV>

<DIV style="position: absolute; left: 165px; top: 436px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_bottom.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_bottom.png" width="280" height="8" border="0" alt="">
</span>
</DIV>

<DIV style="position: absolute; left: 475px; top: 436px; z-index:4;">
<span style="width:280px;height:8px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/frame_bottom.png');">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="/images/frame_bottom.png" width="280" height="8" border="0" alt="">
</span>
</DIV>';}
return(vFade);
}
</script>

Rambo Tribble

6:22 pm on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The filter:progid~etc. is ActiveX, and not available in Netscape.

If your string you are assigning to vFade is carried out across lines, you must break lines by closing your single quotes, using concatenation (use the +) then open the single quotes on the next line.

RonPK

6:27 pm on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



vFade='<DIV style="position: absolute\; left: 165px\; top: 142px\; z-index:4\;">
<img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)\;" src="/images/frame_top.png" width="280" height="8" border="0" alt="">
</DIV>
[...] ';

* There is no need for the \ before the ;

* you can't use line breaks (carriage returns) in strings. That is what causes the error. Either put everything between the opening ' and the closing ' on one line, or use a concatenation operator:

var vFade = 'this is going to be a very very very very ';
vFade += 'long line.';

mylungsarempty

12:18 am on Apr 1, 2004 (gmt 0)

10+ Year Member



Thankyou for clearing this up for me. The slashes were an attempt to rule out the semi-colons as being the cause. I appreciate everyone's input.

mylungsarempty

4:45 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



I'm getting an error now because of the way my single and double quotes are embedded for my purposes... how do i cancel something, with a \ or with a /

or do i know what i'm even talking about

RonPK

7:51 pm on Apr 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



\

Rambo Tribble

11:42 pm on Apr 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, the \ is the escape character. It is used to place characters, like single and double quotes, in a text string so they don't interfere with the use of quotes as string delimiters. They also add characters like carriage returns (\n) or tabs (\t).