Submit a form and refresh to the bottom of the pag

2019-09-15 18:09发布

问题:

when submitting a form in php i am using: "header('Location: contact.php');" to redirect back to the current page after hitting submit. However the form is at the bottom of the page and each time submit is hit it is redirected back to the top of the page. is there anyway to redirect back to the bottom of the page?

回答1:

Yes, You can take a id to part of a page you want to return to and then return to it, see following code:

for example you want to return to bellow div:

<div id="bottom"></div>

your php code to redirect to this:

header('Location: contact.php#bottom');


回答2:

You could check if your page was the pre ious page with window.history and if so, scroll down with window.scroll to.

I really recommend to not to that and use AJAX



标签: php html forms