Here is a case: if a link contains a word, then direct the user to some anchor on the page. I needed this for ChronoForms in Joomla – when filling out the form, the page was updated, and it was necessary to return the user to filling out the form or viewing the status of sending the letter.
Here is the solution:
<script type="text/javascript"> jQuery(document).ready(function ($) { $(document).ready(function () { if(window.location.href.indexOf("chronoform") > -1) { const el = document.getElementById('chronoform_request'); el.scrollIntoView(); } }); }); </script>
where chronoform is a piece of the link that was added after filling out the form, and chronoform_request is the ID of the form that needs to be scrolled to.
This one:
jQuery(document).ready(function ($) { *** });
is needed to avoid jQuery errors $ is not a function