F
F
fapchat2021-11-08 01:47:15
css
fapchat, 2021-11-08 01:47:15

How to force input type="submit" in Chrome not to scroll the screen to the top of the document?

event.preventDefault();/ return false;- impossible, otherwise - it will be bad
Tried to use this code

let submits = document.querySelectorAll('input[type="submit"]');

 submits.forEach(submit => {
   submit.onclick = stopScrolling;
 });

  function stopScrolling(event) {
    alert(window.scrollY);
    window.scrollTo(window.scrollY, window.scrollX);

  }

And tried to use other properties. For example, window.pageXOffset, window.pageYOffset, but such code cannot work. So tell me what to do? And why is everything so sad in chrome? Everything is fine in Mozilla. There, after clicking on input type="submit" The screen will scroll to the section with the form. Haven't tested in other browsers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2021-11-08
@fapchat

submitdoesn't scroll anything, it submits the form . When the form is submitted, the page is reloaded .
Those. as a crutch, you can memorize the submitcoordinates of the scroll before (eg in localStorage) and scroll through them when loading .

N
Nadim Zakirov, 2021-11-08
@zkrvndm

Do you happen to have a hash mark in the action of the form?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question