←back to thread

1901 points l2silver | 1 comments | | HN request time: 0.364s | source

Maybe you've created your own AR program for wearables that shows the definition of a word when you highlight it IRL, or you've built a personal calendar app for your family to display on a monitor in the kitchen. Whatever it is, I'd love to hear it.
Show context
hohg ◴[] No.35746914[source]
@dang regarding pagination

    // Get the anchor tag element
    const anchorTag = document.querySelector('.morelink');

    // Add a scroll event listener to the window object
    window.addEventListener('scroll', () => {
      // Check if the user has scrolled to the bottom of the page
      if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
        // Fetch the content from the URL stored in the anchor tag's href attribute
        const xhr = new XMLHttpRequest();
        xhr.open('GET', anchorTag.href, true);
        xhr.onload = () => {
          // Append the fetched content to the page
          const div = document.createElement('div');
          div.innerHTML = xhr.responseText;
          document.body.appendChild(div);
        };
        xhr.send();
      }
    });
replies(3): >>35749160 #>>35758742 #>>35759338 #
1. mdaniel ◴[] No.35759338[source]
> div.innerHTML = xhr.responseText;

Did you test this? Because CORS aside, that sure does look like it will append the whole of page 2 to the body of page 1 and get progressively worse as one reaches the pagination of page 2. It would be more code (and memory pressure) but I believe the correct impl of any such trickery would be to reach into the actual table of page 2 and jam that into the body of page 1