473,414 Members | 1,675 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,414 software developers and data experts.

javascript position page

set scroll position in javascript.

Is there a way to do this without using document.location, example.

document.location = "#gohere"
<a name="gohere">
Jul 20 '05 #1
3 14139
just use an <a href> tag, no need for JS here

<a href="pagename.html#gohere">Link</a>

Stu

"bigbinc" <bi*****@hotmail.com> wrote in message
news:d1**************************@posting.google.c om...
set scroll position in javascript.

Is there a way to do this without using document.location, example.

document.location = "#gohere"
<a name="gohere">

Jul 20 '05 #2
In IE only, you can use the scrollIntoView method.

object.scrollIntoView()

You can also pass an argument to specify scrolling the element to the
top or bottom of the page. For more information, see ...

http://msdn.microsoft.com/workshop/a...methods/scroll
intoview.asp

Not ideal if you are publishing to the internet, but if it's an intranet
or controlled environment then you could use it.

Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
bigbinc wrote:
set scroll position in javascript.

Is there a way to do this without using document.location, example.

document.location = "#gohere"
<a name="gohere">


Using a function taking the name of an anchor:
function pageXY( el)
{
var XY={x:0, y:0};
for( var node = el; node; node=node.offsetParent)
{ XY.x += node.offsetLeft;
XY.y += node.offsetTop;
}
return XY;
}
function gotoName( name)
{
var anchors, anchor, XY;
anchors=document.anchors;
anchor=anchors[name];

if(!anchor) // IE sucks
{ for( var i = 0; i < anchors.length; ++i)
{ if(anchors[i].name==name)
{ anchor = anchors[i];
break;
}
}
}
if(!anchor)
{ if( document.getElementById)
anchor=document.getElementById(name);
else if( document.all) // untested
anchor=document.all[name];
}
if(anchor)
{ XY = pageXY(anchor);
window.scrollTo(XY.x, XY.y);
}
}

----

This contains some "paranoid" code in that it searches for an element
with the same id as the supplied name if it cannot find a matching
anchor, and makes no attempt to fix broken positioned offset chains as
may be encountered for anchors within tables using padding and borders,
or anchors within relatively positioned elements under MSIE.

Found in testing:
* IE 6 doesn't appear to implement document.anchors as an HTMLCollection
and didn't return a named anchor property,
* As I understand it, document.getElementsByTagName("A") should return a
nodeList without named lookup (part of the NamedNodeMap and
HTMLCollection interfaces). Not included in above code, Mozilla returned
an HTMLCollection, Opera 7 a "nodeList" with named lookup support and
IE6 some kind of index collection *with* named lookup.

For trivial comment, document.location was deprecated in favor of
window.location as far back as javascript 1.3, although all three
browsers tested seem to support it.

HTH
Dom
Jul 20 '05 #4

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

Similar topics

15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
by: Prescott | last post by:
I want to execute a javascript function that will set a value in the parent window from the child widow where its called and then post the form to the server. I seem to be able to execute one or...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
by: Mise en place du service Groupes | last post by:
Hi, Ever had pb with Javascript that works in Fx and not in I.E. ? I try to have a javascript that position an element in the top of an HTML Page. The object is to load the javascipt that...
3
by: crazystone82 | last post by:
Hi friends, i need to drag a file from desktop and drop into web page.actually i had did a JS for dragging the images around the web page,but i dont know how to drag the file and drop it into...
2
by: verci | last post by:
Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows XP Pro SP2, IE 7, VS2005, ASP.net 2.0 The problem is that I'm trying to display this news scroller made in a Javascript...
2
by: Peter Michaux | last post by:
Douglas Crockford doesn't seem to like JavaScript's built-in syntax for building new objects based on a prototype object. The constructor function, its prototype property and the "new" keyword all...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.