Home  >  Q&A  >  body text

The content the user left last time will be automatically restored and the website will jump to that content

In HTML and CSS, how can I make it so that when a user leaves and reopens the page after viewing it, the page will be loaded in the paragraph that the user last focused on?

P粉587780103P粉587780103372 days ago486

reply all(1)I'll reply

  • P粉865900994

    P粉8659009942023-09-14 10:28:58

    It’s impossible to do this with just HTML and CSS. But it is possible using front-end JavaScript and cookies.

    Regularly save the scrollTop and scrollLeft of the main content element to the document cookie. When the document loads, parse the cookie and use the scrollTo method to resume scrolling.

    reply
    0
  • Cancelreply