Answer the question
In order to leave comments, you need to log in
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);
}
Answer the question
In order to leave comments, you need to log in
submit
doesn't scroll anything, it submits the form . When the form is submitted, the page is reloaded .
Those. as a crutch, you can memorize the submit
coordinates of the scroll before (eg in localStorage
) and scroll through them when loading .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question