473,383 Members | 1,978 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,383 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 14138
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.