0

When you press the edit button, it opens a new window that's exactly the same as the former but editable. I want to be able to have the scroll position of the new window be the same as the original. How can I keep the scroll position the same? I think I need to use localStorage?

          $tmpOnClickJs = <<<JAVASCRIPT
          window.open('/views/record/edit/index.php?recordId={$this->recordId}');
  JAVASCRIPT;

          return <<<HTML
              <i
                  id="editRecordIcon"
                  class="fas fa-edit fa-2x pointer m-2"
                  data-toggle="tooltip"
                  data-original-title="Edit"
                  data-container="body"
                  onclick="{$tmpOnClickJs}"
              ></i>
  HTML;
Gabriel Shen
  • 99
  • 2
  • 6
  • The scroll position of the page shouldn't change if new content is created/shown using javascript. Try creating a div hidden by css then unhide when the edit button is pressed. – SJacks Sep 23 '20 at 15:50
  • You probably don't want local storage, that's more meant to be shared across multiple instances (of a site) and not for a value dedicated to a single page-to-page thing. Instead, just pass the current [window's scroll position](https://stackoverflow.com/a/3464890/231316) in the querystring to the new page, and then [on page load, look for that value and scroll](https://stackoverflow.com/a/19996392/231316). – Chris Haas Sep 23 '20 at 17:14
  • @ChrisHaas where do I add the window.onload? right below the window.open()? – Gabriel Shen Sep 23 '20 at 18:56

0 Answers0