View Single Post
  #1 (permalink)  
Old November 21st, 2007, 11:53 AM
kwilliams kwilliams is offline
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Converting Client-side to Server-side Code

I'm trying to convert code that was originally client-side into server-side code. It pulls data from several XML feeds, and then uses variables from that data in a news scroller. When client-side with static variables, the data scrolls every 5 seconds. But the server-side example doesn't scroll at all.

Almost everything works fine, except for the setTimeout. When I load the code listed below, I receive this error:
Microsoft JScript runtime error '800a1391'
'window' is undefined
/scroller.asp, line 173

I realize that 'window' is a browser object that cannot be used in server-side code, but I'm not sure how to adjust my code to make it work. If anyone could let me know what I'm doing wrong, that would be great. Thanks.

var pausecontent=new Array()
        var strMessage1 = "This is message 1";
        var strMessage2 = "This is message 2";
        var strMessage3 = "This is message 3";
        pausecontent[0]='<strong>Title 1: ' + strMessage1 + '</strong>'
        pausecontent[1]='<strong>Title 2: ' + strMessage2 + '</strong>'
        pausecontent[2]='<strong>Title 3: ' + strMessage3 + '</strong>'

        * Pausing up-down scroller- © Dynamic Drive (
        * This notice MUST stay intact for legal use
        * Visit for this script and 100s more.

        function pausescroller(content, divId, divClass, delay){
        this.content=content //message array content
        this.tickerid=divId //ID of ticker div to display information
        this.delay=delay //Delay between msg change, in miliseconds.
        this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
        this.hiddendivpointer=1 //index of message array for hidden div
        Response.Write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
        var scrollerinstance=this

        //*****************THIS IS WHERE I'M HAVING THE PROBLEM****************************

        if (window.addEventListener) //run onload in DOM2 browsers
        window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
        else if (window.attachEvent) //run onload in IE5.5+
        window.attachEvent("onload", function(){scrollerinstance.initialize()})
        else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
        setTimeout(function(){scrollerinstance.initialize()}, 500)

        // -------------------------------------------------------------------
        // initialize()- Initialize scroller method.
        // -Get div objects, set initial positions, start up down animation
        // -------------------------------------------------------------------

        //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)*2)+"px"
        this.getinline(this.visiblediv, this.hiddendiv)"visible"
        var scrollerinstance=this
        if (window.attachEvent) //Clean up loose references in IE
        window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
        setTimeout(function(){scrollerinstance.animateup()}, this.delay)

        // -------------------------------------------------------------------
        // animateup()- Move the two inner divs of the scroller up and in sync
        // -------------------------------------------------------------------

        var scrollerinstance=this
        if (parseInt(>(this.visibledivtop+5)){"px""px"
        setTimeout(function(){scrollerinstance.animateup()}, 50)
        this.getinline(this.hiddendiv, this.visiblediv)
        setTimeout(function(){scrollerinstance.setmessage()}, this.delay)

        // -------------------------------------------------------------------
        // swapdivs()- Swap between which is the visible and which is the hidden div
        // -------------------------------------------------------------------

        var tempcontainer=this.visiblediv

        pausescroller.prototype.getinline=function(div1, div2){"px", div1.offsetHeight)+"px"

        // -------------------------------------------------------------------
        // setmessage()- Populate the hidden div with the next message before it's visible
        // -------------------------------------------------------------------

        var scrollerinstance=this
        if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
        setTimeout(function(){scrollerinstance.setmessage()}, 100)
        var i=this.hiddendivpointer
        var ceiling=this.content.length
        this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1

        pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
        if (tickerobj.currentStyle)
        return tickerobj.currentStyle["paddingTop"]
        else if (window.getComputedStyle) //if DOM2
        return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
        return 0