views:

300

answers:

1

Hello,

I'm having a problem with some of our users getting a javascript error popup when accessing our online store via our software. The software uses a standard WebBrowser control and the users getting the error include those with IE versions 6,7 and 8 and .net 2 and 3.5. The error does not appear when they access the store directly through IE. The error does not appear for me in either FF or IE8 or through our software.

The error occurs when the user looks at a product's detailed page and only when this page includes a javascript clip player.

The error itself simply says:

Line: 1 Character: 59 Error: Expected ')' Code: 0

Line 1 of the file is the doctype, so:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

This appears in every single page, so I don't see how it can be the cause when the error only appears on pages with the clip player.

The html relating to the clip player is below. It's using nVelocity, so that's what all the $siteroot stuff is about. I've double checked that all the correct brackets exist.

<script type="text/javascript">
                //<![CDATA[
                    var myListener = new Object();

                    /**
                     * Initialisation
                     */
                    myListener.onInit = function()
                    {
                        this.position = 0;
                    };
                    /**
                     * Update
                     */
                    myListener.onUpdate = function()
                    {                           
                        var isPlaying = (this.isPlaying == "true");
                        document.getElementById("playerplay").style.display = (isPlaying)?"none":"block";
                        document.getElementById("playerpause").style.display = (isPlaying)?"block":"none";
                    };

                    function getFlashObject()
                    {
                        return document.getElementById("myFlash");
                    }
                    function play()
                    {
                        if (myListener.position == 0) {
                            getFlashObject().SetVariable("method:setUrl", "/appsite/Files/Clips/$story.Value.ClipPath");
                        }
                        getFlashObject().SetVariable("method:play", "");
                        getFlashObject().SetVariable("enabled", "true");
                    }
                    function pause()
                    {
                        getFlashObject().SetVariable("method:pause", "");
                    }
                    function stop()
                    {
                        getFlashObject().SetVariable("method:stop", "");
                    }
                    function setPosition()
                    {
                        var position = document.getElementById("inputPosition").value;
                        getFlashObject().SetVariable("method:setPosition", position);
                    }
                    function setVolume()
                    {
                        var volume = document.getElementById("inputVolume").value;
                        getFlashObject().SetVariable("method:setVolume", volume);
                    }
                //]]>
                </script>
                <!--[if IE]>
                <script type="text/javascript" event="FSCommand(command,args)" for="myFlash">
                eval(args);
                </script>
                <![endif]-->

                <object class="playerpreview" id="myFlash" type="application/x-shockwave-flash" data="$siteroot/content/player_mp3_js.swf" width="1" height="1">
                    <param name="movie" value="$siteroot/content/player_mp3_js.swf" />
                    <param name="AllowScriptAccess" value="always" />
                    <param name="FlashVars" value="listener=myListener&amp;interval=500" />
                </object>

                <li><div id="playercontroller">
                    <div id="playerplay"><a href="javascript:play()" ><img src="$siteroot/content/images/clipplay.png" style="vertical-align: middle;"/></a> Play a short clip.</div>
                    <div id="playerpause" style="display:none;"><a href="javascript:pause()"><img src="$siteroot/content/images/clippause.png" style="vertical-align: middle;"/></a> Pause clip.</div>
                </div></li> 
A: 

This looks like it's more to do with your flash code than your Javascript code. You say "some of [your] users" are getting the issue so it's an intermittent problem most likely caused by a single specific action on the site. The following code is likely where the issue is:

<script type="text/javascript" event="FSCommand(command,args)" for="myFlash"> 
    eval(args); 
</script>

Your flash code fires this event and then Javascript calls eval on the args parameter that is sent by flash. So it will be difficult to identify this issue from your javascript code. You could try and debug this by wrapping a try/catch around the eval statement and then outputting the value of args somewhere so that you view the erroneous code. I would also suggest replacing eval(args); with eval('('+args+')');, since that has fixed problems for me when parsing JSON in the past.

Andy E