Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onLoad, scrollTo, and Safari

    This function will center the browser window on the input coordinate. I've tested it in Mozilla Firefox, Explorer, and Safari (on both PC and Mac where applicable). It works on all of these browsers when accessed from an <a> tag.

    Code:
    function centerScroll(xx,yy){
    
    var xpos
    var ypos
    
    xpos = xx - document.body.clientWidth/2
    ypos = yy - document.body.clientHeight/2
    
    scrollTo(xpos, ypos)
    }

    I am still having one problem, however, in Safari. When I try to access this function using onLoad, it doesn't work at all. Here's my body tag:

    Code:
    <body onLoad="javascript:centerScroll(1000,1000)">

    It appears that Safari must not like the way I stated the onLoad line. Any ideas?

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure as I do not have Safari available but firstly, onload is not mixed cased and secondly, when using a javascript event handler there is no need to use the javascript protocol...

    Try: <body onload="centerScroll(1000,1000)">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •