lawrence wrote:
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.
Thanks for clarifying this.
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 ph******@yahoogroups.com, Bob Sawyer <bobsawyerdotcom@y...>
wrote
I don't think it's anything in the PHP - I think it's
your javascrpt, particularly this function:
------------------
function scrolltop() {
location = document.body.scrollTop;
document.body.scrollTop 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.
if (location == 0) location =
document.documentElement.scrollTop;
if (location == 0) location = window.pageYOffset;
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(){instruction[s];} else structure)
depending on the support for a particular object property.
document.getElementById('scrollmenu').style.pixelT op
= location;
I can assure you that Netscape 7.x and Mozilla-based browsers do not
support pixelTop.
gTimer1 = window.setTimeout('scrolltop()',1000);
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.
}
------------------
I'm terrible with javascrpt but I think that's where
your "0" is coming from...
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.
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:
#idMenuFixedInViewport {width: 250px; position: absolute; top: 100px;
left: 150px; border: 2px solid green; background-color: white;}
body>div#idMenuFixedInViewport {position: fixed;}
and in your HTML code:
<div id="idMenuFixedInViewport">(...)</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):
http://www10.brinkster.com/doctorunc...tionFixed.html
DU