473,383 Members | 1,821 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.

Sroll to particular element

KJ
Hello all,

Is it possible to scroll a window (a frame, actually) to a particular
element. For example, I have some elements near the bottom of the page
(which requires scrolling, maybe 2 or 3 pages worth to get to this
content), and I'd like to scroll the window to that element (in this
case, the element has markup: <strong class=highlight>some
text</strong>)?

Thanks,
-KJ

Dec 14 '06 #1
12 1258
KJ wrote:

Is it possible to scroll a window (a frame, actually) to a particular
element. For example, I have some elements near the bottom of the page
(which requires scrolling, maybe 2 or 3 pages worth to get to this
content), and I'd like to scroll the window to that element (in this
case, the element has markup: <strong class=highlight>some
text</strong>)?
<a href="#ANCHOR">go to bottom</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<a name="ANCHOR">text</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>

--
Bart

Dec 14 '06 #2
KJ
Is it possible to achieve this programmatically (without requiring a
user click)?

Bart Van der Donck wrote:
KJ wrote:

Is it possible to scroll a window (a frame, actually) to a particular
element. For example, I have some elements near the bottom of the page
(which requires scrolling, maybe 2 or 3 pages worth to get to this
content), and I'd like to scroll the window to that element (in this
case, the element has markup: <strong class=highlight>some
text</strong>)?

<a href="#ANCHOR">go to bottom</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<a name="ANCHOR">text</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>

--
Bart
Dec 14 '06 #3
KJ wrote:
Bart Van der Donck wrote:
<a href="#ANCHOR">go to bottom</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<a name="ANCHOR">text</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
Is it possible to achieve this programmatically (without requiring a
user click)?
Sure, by linking to that page from elsewhere as PAGENAME.HTML#ANCHOR.

Just don't refresh to PAGENAME.HTML#ANCHOR or you will get an endless
loop. If your page is the index of a directory, you could modify the
index to PAGENAME.HTML#ANCHOR (on Apache, that's "DirectoryIndex
PAGENAME.HTML#ANCHOR" in an .htacess file in the directory).

--
Bart

Dec 14 '06 #4
KJ
Hi Bart,

I can't do this using a link of any kind; I need to do this using a
javascript call of some kind. Is this possible?

Bart Van der Donck wrote:
KJ wrote:
Bart Van der Donck wrote:
<a href="#ANCHOR">go to bottom</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
<a name="ANCHOR">text</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br><br><br>
Is it possible to achieve this programmatically (without requiring a
user click)?

Sure, by linking to that page from elsewhere as PAGENAME.HTML#ANCHOR.

Just don't refresh to PAGENAME.HTML#ANCHOR or you will get an endless
loop. If your page is the index of a directory, you could modify the
index to PAGENAME.HTML#ANCHOR (on Apache, that's "DirectoryIndex
PAGENAME.HTML#ANCHOR" in an .htacess file in the directory).

--
Bart
Dec 14 '06 #5
"KJ" <n_**********@mail.comwrote in news:1166129002.562043.208020@
80g2000cwy.googlegroups.com:
I can't do this using a link of any kind; I need to do this using a
javascript call of some kind. Is this possible?
Using javascript,

document.location.href = "PAGENAME.HTML#ANCHOR";

will direct the browser to load PAGENAME.HTML and scroll down to #ANCHOR
Dec 15 '06 #6
Jim Land (NO SPAM) wrote:
[...]
document.location.href = "PAGENAME.HTML#ANCHOR";
will direct the browser to load PAGENAME.HTML and scroll down to #ANCHOR
Boobytrap. You'll end up in an endless loop because the page will keep
refreshing to PAGENAME.HTML#ANCHOR.

--
Bart

Dec 15 '06 #7
KJ wrote:
Bart Van der Donck wrote:
>Just don't refresh to PAGENAME.HTML#ANCHOR or you will get an endless
loop. If your page is the index of a directory, you could modify the
index to PAGENAME.HTML#ANCHOR (on Apache, that's "DirectoryIndex
PAGENAME.HTML#ANCHOR" in an .htacess file in the directory).
I can't do this using a link of any kind; I need to do this using a
javascript call of some kind. Is this possible?
if (!/#ANCHOR$/.test(document.location.search.substring(1))) {
document.location.href = "PAGENAME.HTML#ANCHOR"
}

--
Bart

Dec 15 '06 #8
Bart Van der Donck a écrit :
KJ wrote:
Bart Van der Donck wrote:
Just don't refresh to PAGENAME.HTML#ANCHOR or you will get an endless
loop. If your page is the index of a directory, you could modify the
index to PAGENAME.HTML#ANCHOR (on Apache, that's "DirectoryIndex
PAGENAME.HTML#ANCHOR" in an .htacess file in the directory).
I can't do this using a link of any kind; I need to do this using a
javascript call of some kind. Is this possible?

if (!/#ANCHOR$/.test(document.location.search.substring(1))) {
document.location.href = "PAGENAME.HTML#ANCHOR"
}

--

Why do you all insist on using page refresh and anchors ? When
something can be done straight foreward, please don't suggest a back
door.

This link might be helpful to solve this problem :

http://radio.javaranch.com/pascarell...293729000.html

And here's another one :

http://www.quirksmode.org/js/layerscroll.html

Happy coding !

Dec 15 '06 #9
KJ wrote:
Is it possible to scroll a window (a frame, actually) to a particular
element. For example, I have some elements near the bottom of the page
(which requires scrolling, maybe 2 or 3 pages worth to get to this
content), and I'd like to scroll the window to that element (in this
case, the element has markup: <strong class=highlight>some
text</strong>)?
Grab the element and call
element.scrollIntoView(true)
that is supported by IE and Mozilla and Opera at least.
IE documentation is here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/scrollintoview.asp>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 15 '06 #10
KJ
Ahh, these last few posts are just the ticket. Thanks to all for
helping out.

-KJ

Martin Honnen wrote:
KJ wrote:
Is it possible to scroll a window (a frame, actually) to a particular
element. For example, I have some elements near the bottom of the page
(which requires scrolling, maybe 2 or 3 pages worth to get to this
content), and I'd like to scroll the window to that element (in this
case, the element has markup: <strong class=highlight>some
text</strong>)?

Grab the element and call
element.scrollIntoView(true)
that is supported by IE and Mozilla and Opera at least.
IE documentation is here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/scrollintoview.asp>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 15 '06 #11
"Bart Van der Donck" <ba**@nijlen.comwrote in
news:11*********************@16g2000cwy.googlegrou ps.com:
Jim Land (NO SPAM) wrote:
>[...]
document.location.href = "PAGENAME.HTML#ANCHOR";
will direct the browser to load PAGENAME.HTML and scroll down to
#ANCHOR
>
Boobytrap. You'll end up in an endless loop because the page will keep
refreshing to PAGENAME.HTML#ANCHOR.
Only if you call that line of JS every time you reload the page. Not a
boobytrap if you call the that line of JS only once.

<button onclick="document.location.href = 'PAGENAME.HTML#ANCHOR'">Click
here to scroll down.</button>

works in IE & FF.
Dec 15 '06 #12
In comp.lang.javascript message
<11*********************@73g2000cwn.googlegroups.c om>, Thu, 14 Dec 2006
07:31:55, KJ <n_**********@mail.comwrote:
>Is it possible to scroll a window (a frame, actually) to a particular
element. For example, I have some elements near the bottom of the page
(which requires scrolling, maybe 2 or 3 pages worth to get to this
content), and I'd like to scroll the window to that element (in this
case, the element has markup: <strong class=highlight>some
text</strong>)?
Yes. <URL:http://www.merlyn.demon.co.uk/js-quick.htmdoes it.

Use an element with a working .focus method and script a call of that
method. It may be wise firstly to set focus to the very top or the very
bottom, to ensure consistent results. Test in various browsers, and/or
read the appropriate specification, wherever it may be.

You may need to add such an element. It cannot be hidden, but it need
not be conspicuous.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ A FAQ for news:comp.lang.javascript.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 15 '06 #13

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

Similar topics

9
by: Timo | last post by:
I'd be grateful for some help on this element addressing question. I want to change the font-size of the "H" of "Hello World" in the following HTML using first-letter, but cannot "reach" the...
2
by: thomasamillergoogle | last post by:
Hi, As you can see from the code below I have a simple js function called getFormElementsinTableRow(rowName). rowName is the ID of the tableRow. I just want to use js to find the child ID's of all...
1
by: Novice | last post by:
Hi all, I'm having some trouble with a XPath query I would like to make I have the following simplified XML <A><B><C name="Test"></C><C name="Test2"></C></B><B><C name="Test"></C></B></A I...
3
by: dba2adm | last post by:
The SNAPSHOT_STATEMENT table function gives the CPU used rows read etc information. How do I know the total number of time the particular statement was executed (as in snapshot_dyn_sql's...
4
by: CodeRazor | last post by:
I am reading an xml file from a URL. I was originally doing this using the XmlDocument class. But this was very slow. The XmlTextReader is meant to be much quicker for forward only retrieval of...
2
by: JU | last post by:
Hello, I am pretty new in XML and I'm studying the DTD definition. I cannot solve a problem, or better, I cannot define what I want in my DTD file. What I would like to do is that something like...
8
by: Sunny | last post by:
Hi, I am creating an Element on page in Firefox. But It gives me an error in Firefox. String contains an invalid character" code: "5 county = document.createElement('"' + countyVMLtext +...
6
by: bgold12 | last post by:
Hey, I just want to make sure that when I remove an element I don't have to worry about the events listeners I added previously to the element. For example: // get the element by its id elem =...
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.