• Dynamic user-defined (persistent) bookmark in a HTML page

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to alt.html on Mon Jul 29 15:43:57 2024
    From Newsgroup: alt.html

    Note: This post is *not* about static bookmarks (id="ref" and '#ref').

    I'd like to dynamically create a bookmark in a HTML page. Upon close
    and re-open of that page that bookmark location should be restored.

    The latter requires using (for example) cookies to store that info.
    But what is the best method to identify some place in the document
    and later use that information to address that place again?

    Actually, all I want is a digital equivalent of a physical bookmark
    in a real book; to continue reading of the book (the HTML document)
    another time.

    I want to use just plain HTML, CSS, JS. (No libraries/frameworks.)

    One way to _maybe_ make that possible is to count the HTML elements
    up to the current, say, clicked location. But that appears not very
    elegant to me - ...if it's feasible at all in the first place.

    Any ideas?

    Janis
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From JJ@jj4public@outlook.com to alt.html on Tue Jul 30 10:07:26 2024
    From Newsgroup: alt.html

    On Mon, 29 Jul 2024 15:43:57 +0200, Janis Papanagnou wrote:
    Note: This post is *not* about static bookmarks (id="ref" and '#ref').

    I'd like to dynamically create a bookmark in a HTML page. Upon close
    and re-open of that page that bookmark location should be restored.

    The latter requires using (for example) cookies to store that info.
    But what is the best method to identify some place in the document
    and later use that information to address that place again?

    Actually, all I want is a digital equivalent of a physical bookmark
    in a real book; to continue reading of the book (the HTML document)
    another time.

    I want to use just plain HTML, CSS, JS. (No libraries/frameworks.)

    One way to _maybe_ make that possible is to count the HTML elements
    up to the current, say, clicked location. But that appears not very
    elegant to me - ...if it's feasible at all in the first place.

    Any ideas?

    Janis

    An URL has no capability to point to a specific page scroll position. So if
    an URL is required, the closest thing is to point the URL to the page which
    was last viewed.
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to alt.html on Tue Jul 30 18:23:18 2024
    From Newsgroup: alt.html

    On 30.07.2024 05:07, JJ wrote:
    On Mon, 29 Jul 2024 15:43:57 +0200, Janis Papanagnou wrote:
    Note: This post is *not* about static bookmarks (id="ref" and '#ref').

    I'd like to dynamically create a bookmark in a HTML page. Upon close
    and re-open of that page that bookmark location should be restored.

    The latter requires using (for example) cookies to store that info.
    But what is the best method to identify some place in the document
    and later use that information to address that place again?

    Actually, all I want is a digital equivalent of a physical bookmark
    in a real book; to continue reading of the book (the HTML document)
    another time.

    I want to use just plain HTML, CSS, JS. (No libraries/frameworks.)

    One way to _maybe_ make that possible is to count the HTML elements
    up to the current, say, clicked location. But that appears not very
    elegant to me - ...if it's feasible at all in the first place.

    Any ideas?

    An URL has no capability to point to a specific page scroll position. So if an URL is required, the closest thing is to point the URL to the page which was last viewed.

    Sorry if I was unclear; let me try to clarify...

    I don't want that position being coded in the URL (but see below
    for an idea with id=BM and the URL containing #BM), I think I'll
    at least have to store (and later restore) that position in/from
    a cookie to keep that bookmark user-defined.

    There's just one (but long) HTML page representing a book with
    chapters and paragraphs. Any URL used is thus just the single
    one that is pointing to that one HTML page.

    With the help of chapter IDs I can jump to the (fixed) chapters
    on the HTML page.

    Within a chapter I want to define a dynamic mark (a "bookmark";
    but not in the sense of a browser's bookmark where AFAICT only
    whole HTML pages are subject to being bookmarked). I want <p>
    entities on that single HTML page bookmarked. (But ideally not
    by setting an 'id' attribute to every existing paragraph.)

    With help of JS it should be possible to get some location in
    the DOM, for example corresponding to the entity clicked on.
    With such information I could for example modify a <p> DOM
    entity on page-load with an 'id="BM"' and initate a reload
    with that mark set 'http...#BM' to get that position loaded.

    This is where I'm looking for some concrete hints. - Thanks.

    BTW: Browsers seem to be able to restore the previous scroll
    position (e.g. when pages are restrored after a crash).

    Janis

    PS: But maybe a JS group is better suited to address that Q ?

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From JJ@jj4public@outlook.com to alt.html on Fri Aug 2 00:29:04 2024
    From Newsgroup: alt.html

    On Tue, 30 Jul 2024 18:23:18 +0200, Janis Papanagnou wrote:
    On 30.07.2024 05:07, JJ wrote:
    On Mon, 29 Jul 2024 15:43:57 +0200, Janis Papanagnou wrote:
    Note: This post is *not* about static bookmarks (id="ref" and '#ref').

    I'd like to dynamically create a bookmark in a HTML page. Upon close
    and re-open of that page that bookmark location should be restored.

    The latter requires using (for example) cookies to store that info.
    But what is the best method to identify some place in the document
    and later use that information to address that place again?

    Actually, all I want is a digital equivalent of a physical bookmark
    in a real book; to continue reading of the book (the HTML document)
    another time.

    I want to use just plain HTML, CSS, JS. (No libraries/frameworks.)

    One way to _maybe_ make that possible is to count the HTML elements
    up to the current, say, clicked location. But that appears not very
    elegant to me - ...if it's feasible at all in the first place.

    Any ideas?

    An URL has no capability to point to a specific page scroll position. So if >> an URL is required, the closest thing is to point the URL to the page which >> was last viewed.

    Sorry if I was unclear; let me try to clarify...

    I don't want that position being coded in the URL (but see below
    for an idea with id=BM and the URL containing #BM), I think I'll
    at least have to store (and later restore) that position in/from
    a cookie to keep that bookmark user-defined.

    There's just one (but long) HTML page representing a book with
    chapters and paragraphs. Any URL used is thus just the single
    one that is pointing to that one HTML page.

    With the help of chapter IDs I can jump to the (fixed) chapters
    on the HTML page.

    Within a chapter I want to define a dynamic mark (a "bookmark";
    but not in the sense of a browser's bookmark where AFAICT only
    whole HTML pages are subject to being bookmarked). I want <p>
    entities on that single HTML page bookmarked. (But ideally not
    by setting an 'id' attribute to every existing paragraph.)

    With help of JS it should be possible to get some location in
    the DOM, for example corresponding to the entity clicked on.
    With such information I could for example modify a <p> DOM
    entity on page-load with an 'id="BM"' and initate a reload
    with that mark set 'http...#BM' to get that position loaded.

    This is where I'm looking for some concrete hints. - Thanks.

    BTW: Browsers seem to be able to restore the previous scroll
    position (e.g. when pages are restrored after a crash).

    Janis

    PS: But maybe a JS group is better suited to address that Q ?

    There are DOM methods and properties to get the position and dimension of
    HTML elements, the viewport, the page height, and the scrollable height. Use the retrieved information to determine at which HTML element to place the bookmark.

    To mention a view...

    https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

    https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight

    https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight

    https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
    --- Synchronet 3.21d-Linux NewsLink 1.2