I've got a newsletter subscription form on my site (just one field, email), built with node.js and express. If JavaScript is enabled, the email is submitted with AJAX and a reply is sent back and a simple 'Success!' message is rendered client side, cute animation and everything.
If JavaScript is disabled, then the data is submitted to the same page the user is currently on, but the page loads at the top. I'd like to render error or success messages where the subscription form is (scrolled down slightly, or on mobile, scrolled down quite a bit).
Is there any way to handle this?
You can add an id
to the element, which you want the page to be scrolled to. Example:
<form id='someID'></form>
and then just redirect to:
'http://yoururl.com/some/page#someID' <--- the #someID part is focusing the element and scrolling to it
So you can just submit to the same page, like now, but with #someID
at the end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.