473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:

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;
if (location == 0) location =
document.documentElement.scrollTop;
if (location == 0) location = window.pageYOffset;
document.getElementById('scrollmenu').style.pixelT op
= location;
gTimer1 = window.setTimeout('scrolltop()',1000);
}
------------------

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.
Jul 23 '05 #1
2 1671
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. 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;
if (location == 0) location =
document.documentElement.scrollTop;
if (location == 0) location = window.pageYOffset;
document.getElementById('scrollmenu').style.pixelT op
= location;
gTimer1 = window.setTimeout('scrolltop()',1000);
}
------------------

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.


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.
So it's unlikely. But it is worth looking at. I'll repost all this to
a Javascript list.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2
DU
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
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lukeo | last post by:
I'm shelling out to an .asp (or htm) page from an application. I want to show this in a window without the address bar, etc... Is there a way I can redirect this page using javascript to a page...
1
by: relaxedrob | last post by:
Howdy All! I am really stuck with this one - I want to completely create a table within JavaScript and insert it into the document, with onMouseOut and onMouseOver handlers in the table rows. ...
1
by: Kjell Breimo | last post by:
Hi, I have made a selectbox (<Select....><option...>...) with size=1(It has to be size=1). It contains about 40 elements. It is placed on the top of my webpage abd I would like to see as many...
3
by: David Rwj Cherry CS2000 | last post by:
is there any way to disable or lock vertical scroll bars on a browser window? im a newbie and i just don't want them to appear on my screen. sometimes they appear on IE but not on mozilla. any...
2
by: Elisa | last post by:
I have two images, each with defined CSS hover states. I would like a mouseover on one image to trigger the hover state of the other image. Is this possible using javascript? If so, how? Any...
1
by: Rob Webster | last post by:
Hi, is there a way using JavaScript to tell a textarea to scroll to the end of it's contents? I'm implementing something that looks like messenger using web forms, after each post the chat area...
1
by: alvinpoon | last post by:
Hello, I have a problem setting the scrollbar position of a div region on a webpage which is posted at http://www.geocities.com/virtuosity999/Logon.htm If the page is loaded with Netscape,...
6
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.