473,786 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to remember a users last position in the document?

Suppose you got a really long page and you'd like to enable
the user (supposedly, there's only one but if it's not to
difficult we could extend that to any number) not to have
to scroll to the last position in the document he/she was
viewing but simply auto-jump him/her to it. Is that doable
at all using JS?

I guess it would be somewhere in the vicinity of:
- remember every scroll
- save the line number to the users HDD
- at next visit jump to the saved line

I have seen pages that "remember" me by cookies so i
guess that's a good start for the solution but the rest of
the issue i'd love to get some help with.

I've worked with Java and C++ for a few years so the
prorgamming issues are not a problem. However, i'm
still rather new to JS.

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #1
16 1618
You could use anchors.

http://www.askblax.com

Jul 23 '05 #2
Konrad Viltersten wrote:
Suppose you got a really long page and you'd like to enable
the user (supposedly, there's only one but if it's not to
difficult we could extend that to any number) not to have
to scroll to the last position in the document he/she was
viewing but simply auto-jump him/her to it. Is that doable
at all using JS?

I guess it would be somewhere in the vicinity of:
- remember every scroll
- save the line number to the users HDD
- at next visit jump to the saved line

I have seen pages that "remember" me by cookies so i
guess that's a good start for the solution but the rest of
the issue i'd love to get some help with.

I've worked with Java and C++ for a few years so the
prorgamming issues are not a problem. However, i'm
still rather new to JS.


You could store the value of scrollTop and pageYOffset and a page
identifier (say filename) in a cookie onunload and, when the user
requests on their next visit, scroll the page to that location.

Have a poke around quirksmode in the viewport - browser compatibility
page.

<URL:http://www.quirksmode. org/> (frames)

<URL:http://www.quirksmode. org/viewport/compatibility.h tml> (direct)
--
Fred
Jul 23 '05 #3
askMe wrote:
You could use anchors.

Do you mean
a) dynamically set anchors that are changed at every scroll
or
b) anchors as in <a href="bip.html" >bip</a>
?

If a - i'd like to know more. I don't seem to find any good
info on that topic. If b - no really a solution for my part
depending on various reasons.

Thanks for trying, anyway.
--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #4
> Have a poke around quirksmode in the viewport - browser
compatibility page.

<URL:http://www.quirksmode. org/> (frames)

<URL:http://www.quirksmode. org/viewport/compatibility.h tml>
(direct)

Hmmm... The way i see it there's virtually no standard being
followed by the different browsers (that, or there is one
that most browsers have choosen not to follow very strictly
for one reason or another). Sad...

Thanks, by the way.

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #5
Konrad Viltersten wrote:
askMe wrote:
You could use anchors.

Do you mean
a) dynamically set anchors that are changed at every scroll
or
b) anchors as in <a href="bip.html" >bip</a>
?


(snip)

He has no idea what he means. Notice his accompanying code sample.

Fred's solution was correct. Here's a somewhat dated example:

http://webreference.com/js/tips/991203.html

Use ppk's properties (with object detection) for almost total browser
coverage and proper degradation.

Jul 23 '05 #6
RobB wrote:

(snip)
Fred's solution was correct. Here's a somewhat dated example:

http://webreference.com/js/tips/991203.html

Use ppk's properties (with object detection) for almost total browser
coverage and proper degradation.


OK, try this [untested].

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">

function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTSt ring() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}

function getCookie(name) {
var dc = document.cookie ;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(pref ix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie .indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.sub string(begin + prefix.length, end));
}

window.onload = function()
{
var y_scroll = getCookie('y_sc roll');
if (y_scroll)
scrollTo(0, parseInt(y_scro ll, 10));
}

window.onunload = function()
{
var y_scroll =
window.pageYOff set ?
pageYOffset :
document.docume ntElement
&& 'undefined' != typeof document.docume ntElement.scrol lTop ?
document.docume ntElement.scrol lTop :
document.body ?
document.body.s crollTop :
null;
var now = new Date();
now.setTime(now .getTime() + 365 * 24 * 60 * 60 * 1000);
setCookie('y_sc roll', y_scroll || '', now);
}

</script>
</head>
<body>
<pre>
<script type="text/javascript">
var z = 0;
while (z++ < 100)
document.writel n(z);
</script>
</pre>
</body>
</html>

Jul 23 '05 #7
RobB wrote:
Konrad Viltersten wrote:
askMe wrote:
You could use anchors. Do you mean

<snip> (snip)

He has no idea what he means. Notice his accompanying
code sample.
There is no need to go as far as looking at code, the positing style
alone is sufficient to indicate a worthless response.
Fred's solution was correct.
The problem with Fred's suggestion is that the degree to which a page
has previously been scrolled by a user will depend in part of the layout
and flow of the document. So re-visiting the site with a browser window
of different dimensions will tend to invalidate the scroll offsets from
previous visits. And if the user has changed their default (or current)
font size between visits then previous scroll offsets will also no
longer be valid.

It may be that the real solution to this problem is the provision of
internal navigation on a page, so that the use can quickly get back to
where they remember being.

<snip> Use ppk's properties (with object detection) for almost
total browser coverage and proper degradation.


LOL

Richard.
Jul 23 '05 #8
> OK, try this [untested].

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<snip>

Well, it didn't work so now i hate you!

Just kidding. It really doesn't work but i hardly hate people
at all, especially when they try to help my sorry donkey.
I put a simple altert('somethi ng') in the two functions handling
loading and unloading and what i discovered was that
a) window.onload = function() {alert('bip');}
gives me an altert (after all the images has been loaded)
but
b) window.onunload = function() {alert('bap');}
produces nothing as i close the window.

So, basically, i have two follow-up questions.
1. How do i make the computer scream as i close the window?
2. How do i make the computer screem BEFORE all the images
on the site are loaded?

The thing is that i follow a cartoon that is issued once a day
and since it's tiresome to switch the days i simply set up a
HTML-doc that handles all the days at once. The thing is that
i'm too lazy to scroll (or use anchor) so i'd like the browser
to remember where i was and jump to that position for me.

Thanks in advance.

By the way, i'm going on a trip to Poland and Czech tomorrow
so if i don't reply until next saturday it's not because i'm not
gratefull. It's because i'm enjoying my girlfriend on vacation.

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #9
Richard Cornford wrote:
RobB wrote:
Konrad Viltersten wrote:
askMe wrote:
You could use anchors.
Do you mean
<snip>
(snip)

He has no idea what he means. Notice his accompanying
code sample.


There is no need to go as far as looking at code, the positing style
alone is sufficient to indicate a worthless response.
Fred's solution was correct.


The problem with Fred's suggestion is that the degree to which a page
has previously been scrolled by a user will depend in part of the

layout and flow of the document. So re-visiting the site with a browser window of different dimensions will tend to invalidate the scroll offsets from previous visits. And if the user has changed their default (or current) font size between visits then previous scroll offsets will also no
longer be valid.

It may be that the real solution to this problem is the provision of
internal navigation on a page, so that the use can quickly get back to where they remember being.

<snip>
Use ppk's properties (with object detection) for almost
total browser coverage and proper degradation.


The OP originally noted:

<quote>
Suppose you got a really long page and you'd like to enable
the user (supposedly, there's only one but if it's not to
difficult we could extend that to any number)...
</quote>

I took that to mean a certain degree of assurance of who those users
might be - and under what conditions this 'solution' might be applied.
In a general sense, you're quite right, HTML is not dtp and any fix
which relies on window configuration is not reliable.
LOL

Richard.


I amuse you? I make you laugh? I'm here to ****in' amuse you?
How am I funny, like a clown? What is so funny about me? What the ****
is so funny about me? Tell me. Tell me what's funny. What percentage of
browsers won't this work with (and degrade acceptably)? (rotfl)

Jul 23 '05 #10

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

Similar topics

0
1704
by: Sascha Folville | last post by:
Hi, I'm trying to transform a XML document to PDF using apache (xerces). I want different formatting for first and last page. My code looks like this: <fo:layout-master-set> <fo:simple-page-master master-name="first" ...> ... </fo:simple-page-master>
0
341
by: Betty Harvey | last post by:
The next meeting of the XML Users Group will be held on Wednesday, May 18, 2005 at the American Geophysical Union (AGU) at 2000 Florida Avenue, N.W., Washington, DC 20009-1277. The meeting starts at 7:00 p.m. and usually last approximately 2 hours. If attending the meeting by Metro, get off the Dupont Circle stop and walk north to Florida Avenue...turn right. There is no cost associated with attending but if you are planning on...
3
11265
by: jason | last post by:
I've got this javascript routine (i found on google - thank you) in an asp.net page that on page reload sets the cursor of a textbox to the last line. It works great! Using a similar concept, I have another application that uses a textbox like an editor window and has a save and other buttons. Problem is - when I save/post/reload, the textbox returns to cursor the top again. How can I preserve / save the exact cursor spot and return...
1
9869
by: Daniel | last post by:
hi, I had an asp:listbox, and everytime i click item inside, the bar automatically go to the top, is there any way to keep the scroll position? I turn on the smartNavigation, it still doesn't work. Thanks ahead.
3
14280
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion with a conversion or correct syntax? I would like to test the current page number and see if it is even or odd - and if it is odd I would like to perform additional steps. I would like to do something like this (assume all namespaces are set):...
4
7802
by: freefly_xml | last post by:
I want to test to see if I am on the last page of a document. In this example it is an invoice. I want to print a different table in REGION AFTER when I am on the last page. I have tried many variations, no luck yet. It seems like it should be an easy thing to do with xsl:choose. Any ideas? Here is one of my attempts. More detail of what the xml, xsl and pdf look like are here: http://www.bangboompow.com/xml/invoice/
2
3270
by: Kevin Burton | last post by:
I don't think I understand the last() function. I have a document that looks like: <Root> <Header>Some text</Header> <Message> <MessageID>1</MessageID> . . . . </Message>
0
1368
by: Betty Harvey | last post by:
NOTE: This is the last meeting of 2006!! The next meeting of the XML Users Group will be held on Wednesday, November 15, 2006 at the American Geophysical Union (AGU) at 2000 Florida Avenue, N.W., Washington, DC 20009-1277. The meeting starts at 7:00 p.m. and usually last approximately 2 hours. If attending the meeting by Metro, get off the Dupont Circle stop and walk north to Florida Avenue...turn right. There is no cost associated...
18
1447
by: Mel | last post by:
What is the best method to achieve this (I am relatively new to vb.net)? Should I use an ini file or the registry? Is there another option available in vb.net that is the preferred way? This application will reside on our network and more than one user could possibly run it so I don't think the local registry is the answer. Basically I just want to remember the options the last user chose on the form and then use those previously used...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9961
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.