I am using a script called RecoverScroll which returns the page to its last loaded point when reloaded.
I am using it on a form page, I need it so that...
When the page errors and a div with an ID of #error-box is present in the markup the RecoverScroll script is ignored and the page jumps to #error-box (which isn't in the url)
alternatively, if I could append #error-box to the url if the #error-box div exists in the markup using js I could use the scripts functionality as intended.
The code to run the script...
Any help will be appreciated, many thanks.
Hi all, has no-one got any ideas on this one?
RecoverScroll might seem slick, but with forms you just need to set focus to a field and the page will scroll to it; maybe write a JS method to "pad" the position so it scrolls to a point above the field, possibly so the field label is visible. Alternatively, if you want to scroll to a particular element, then just find the position and scroll to its top/left offset.
I know this answer doesn't help with RecoverScroll, but you might do well to reevaluate its usefulness.
Thanks for the reply Silkster. In this case due to some bad functionality (which I can't change at this point), the page reloads when some form fields are actioned. The page is set up to focus and move to certain fields but it makes it makes for a bad UX as the page is jumping (and scrolling to them is not much better) so I've installed Recoverscroll to remedy this which works great.
I just need to remove the Recoverscroll functionality IF a div with an ID of #error-box is present in the markup. That or append it to the url in which case I can use Recoverscroll in that instance too. Hope someone can help : )
If anyone needs anymore information let me know.
Hi all, apologies for the bump. Is what I am trying to achieve possible? This is quite urgent now and I will need to look for an alternative if this cannot be achieved.
Could anyone point me in the right direction with this one?
In a nutshell, this is what I need.
IF #error-box doesn't exist
Run recoverscroll (the script from the top message)
IF #error-box does exist
Don't run recoverscroll/do nothing
I hope this makes sense.