Can setting scroll top in IE trigger a redirect in Netscape?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    Can setting scroll top in IE trigger a redirect in Netscape?

    I thought I was fighting a PHP problem, so I asked about this on a PHP
    list, but they felt it was a Javascript problem, so I'm reposting a
    bit of the debate here. Could this Javascript, below, possibly trigger
    a redirect in Netscape, and send the browser to a file called "0".
    Cause what is happening is on load, in Netscape, the page redirects to
    something like:






    --- In php-list@yahoogroup s.com, Bob Sawyer <bobsawyerdotco m@y...>
    wrote[color=blue]
    > I don't think it's anything in the PHP - I think it's
    > your javascrpt, particularly this function:
    >
    > ------------------
    > function scrolltop() {
    > location = document.body.s crollTop;
    > if (location == 0) location =
    > document.docume ntElement.scrol lTop;
    > if (location == 0) location = window.pageYOff set;
    > document.getEle mentById('scrol lmenu').style.p ixelTop
    > = location;
    > gTimer1 = window.setTimeo ut('scrolltop() ',1000);
    > }
    > ------------------
    >
    > I'm terrible with javascrpt but I think that's where
    > your "0" is coming from...[/color]

    Interesting thought. But I don't set the location to 0, I only test to
    see if the scroll top is at 0 pixels. And I'm pretty sure I had this
    function working in Netscape. And at no point do I reference the href.
    So it's unlikely. But it is worth looking at. I'll repost all this to
    a Javascript list.
  • Randy Webb

    #2
    Re: Can setting scroll top in IE trigger a redirect in Netscape?

    lawrence wrote:[color=blue]
    > I thought I was fighting a PHP problem, so I asked about this on a PHP
    > list, but they felt it was a Javascript problem, so I'm reposting a
    > bit of the debate here. Could this Javascript, below, possibly trigger
    > a redirect in Netscape, and send the browser to a file called "0".
    > Cause what is happening is on load, in Netscape, the page redirects to
    > something like:
    >
    > http://www.myDomain.com/0
    >
    >
    >
    >
    > --- In php-list@yahoogroup s.com, Bob Sawyer <bobsawyerdotco m@y...>
    > wrote
    >[color=green]
    >>I don't think it's anything in the PHP - I think it's
    >>your javascrpt, particularly this function:
    >>
    >>------------------
    >>function scrolltop() {
    >> location = document.body.s crollTop;
    >> if (location == 0) location =
    >>document.docu mentElement.scr ollTop;
    >> if (location == 0) location = window.pageYOff set;
    >> document.getEle mentById('scrol lmenu').style.p ixelTop
    >>= location;
    >> gTimer1 = window.setTimeo ut('scrolltop() ',1000);
    >>}
    >>------------------
    >>
    >>I'm terrible with javascrpt but I think that's where
    >>your "0" is coming from...[/color]
    >
    >
    > Interesting thought. But I don't set the location to 0, I only test to
    > see if the scroll top is at 0 pixels. And I'm pretty sure I had this
    > function working in Netscape. And at no point do I reference the href.[/color]

    location and location.href are normally the same thing, in the way that
    you are referencing them. location is a bad variable name. Try changing
    it to thisLocation (anything but location) and see what happens with it.
    [color=blue]
    > So it's unlikely. But it is worth looking at. I'll repost all this to
    > a Javascript list.[/color]


    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • DU

      #3
      Re: Can setting scroll top in IE trigger a redirect in Netscape?

      lawrence wrote:
      [color=blue]
      > I thought I was fighting a PHP problem, so I asked about this on a PHP
      > list, but they felt it was a Javascript problem, so I'm reposting a
      > bit of the debate here.[/color]

      Thanks for clarifying this.

      Could this Javascript, below, possibly trigger[color=blue]
      > a redirect in Netscape, and send the browser to a file called "0".
      > Cause what is happening is on load, in Netscape, the page redirects to
      > something like:
      >
      > http://www.myDomain.com/0
      >
      >
      >
      >
      > --- In php-list@yahoogroup s.com, Bob Sawyer <bobsawyerdotco m@y...>
      > wrote
      >[color=green]
      >>I don't think it's anything in the PHP - I think it's
      >>your javascrpt, particularly this function:
      >>
      >>------------------
      >>function scrolltop() {
      >> location = document.body.s crollTop;[/color][/color]


      document.body.s crollTop is a number (typeof "number"), like 34, 843 or
      3.14159
      location (and location.href) on the other hand is a window property
      storing an uri value like http://www.yahoo.com or
      ftp://www.downloadDomain.com/
      Normally, a good browser/javascript console would (should?) have
      reported a type mismatch somehow. I think the scrollTop value is
      converted into a string.

      Addendum:
      Here, you definitively have a problem. Either you're declaring and
      defining a global variable to store that scrollTop value or you're
      assigning the location property of the window object. Either way, you
      really should not use the "location" identifier like you do in your
      chunck of code.

      [color=blue][color=green]
      >> if (location == 0) location =
      >>document.docu mentElement.scr ollTop;
      >> if (location == 0) location = window.pageYOff set;[/color][/color]

      You seem to be wanting to execute the same instruction for browsers
      implementing different DHTML object model. At least, you should have
      coded a branch code
      (with an if(){instructio n[s];} else structure)
      depending on the support for a particular object property.
      [color=blue][color=green]
      >> document.getEle mentById('scrol lmenu').style.p ixelTop
      >>= location;[/color][/color]

      I can assure you that Netscape 7.x and Mozilla-based browsers do not
      support pixelTop.
      [color=blue][color=green]
      >> gTimer1 = window.setTimeo ut('scrolltop() ',1000);[/color][/color]

      If your user does not scroll the window nor the document view at all,
      say for 200 seconds, then this scrollTop() function will be executed
      anyway and 200 times. For sure, you have to assume that most of the
      time, your users will be reading your document and won't be scrolling
      the document.
      Here, I point out an abuse/poor usage of user's system resource.
      Remember that some people have modest system resources (cpu, RAM, modem
      speed, ISP bandwidth). The ideal would be to reposition that scrollmenu
      of yours when *and only when* a scroll event on the window is fired.
      [color=blue][color=green]
      >>}
      >>------------------
      >>
      >>I'm terrible with javascrpt but I think that's where
      >>your "0" is coming from...[/color]
      >
      >
      > Interesting thought. But I don't set the location to 0, I only test to
      > see if the scroll top is at 0 pixels. And I'm pretty sure I had this
      > function working in Netscape. And at no point do I reference the href.
      > So it's unlikely. But it is worth looking at. I'll repost all this to
      > a Javascript list.[/color]


      First of all, when you post, you should not assume that your solution is
      correct. You should rather first of all describe, explain what you want
      to achieve, and this, preferably along with a provided url where readers
      of your post can see what you have done so far, can check the http
      headers if needed, can verify markup validation of your document.
      Here, I assume you want that scrollmenu of yours to remain fixed in the
      browser viewport, at the top of the viewport. If so, then, say, in your

      CSS stylesheet:
      #idMenuFixedInV iewport {width: 250px; position: absolute; top: 100px;
      left: 150px; border: 2px solid green; background-color: white;}
      body>div#idMenu FixedInViewport {position: fixed;}

      and in your HTML code:
      <div id="idMenuFixed InViewport">(.. .)</div>

      would do the trick for browsers supporting position: fixed;. You would
      then need a javascript function for MSIE 5+: I did it with 10 lines of code.

      Second, when you code, best is to avoid duplicating the name of
      variables with keyword attributes, methods, functions. This for many
      reasons: code readability, code reviewing by others, and, very
      important, scope of variables not interacting/conflicting with keyword
      attributes/methods/functions.
      Here, location as a global variable and scrollTop as a function name are
      bad names. In some cases, browsers can confuse the scope of function
      name with a property or method of the window object: I know a precise
      case of such.

      Third, one way to reduce conflicts, memory load, memory management on
      the user's side is to scope variables and references wisely: a local
      variable is used differently from a global variable. Whenever possible,
      reduce the number of global variables to a minimum.

      The following file has been tested, is valid, should meet your webpage
      requirements and is working on Opera 7.51, Mozilla 1.7 RC2, K-meleon
      0.8.2, MSIE 6 SP1a, NS 7.1 (and it should work in a large number of
      browsers):



      DU

      Comment

      Working...