简体   繁体   中英

How to jump to anchor tag on php page after html form submits

My index.php page uses a template called template.html, and this html file has a form in it. The first line of the form is:

<form name="search" method="get" action="thumbnails.php?#myAnchor">

thumbnails.php also uses template.html as a template. When a user submits the form on the index page, I want it to redirect to thumbnails.php (as it does now) but then go to the anchor I've written in template.html like this:

 <a name="myAnchor"></a>

You can test it for yourself below, just search for "nature" in the top search box and it'll redirect you to the top of thumbnails.php but I want it to scroll down to the anchor tag embedded in the template file (seen in thumbnails.php source code) -- My Site

Here is the link to thumbnails.php and here's the link to template.html

I've read tons of solutions but nothing seems to work. Ideas?? Thank you

As Dai said in their comment ,

[...] the HTML5 specification removed the name="" attribute from the <a> element ( obsolete note ). The specification for fragment scrolling gives preference to id over name and only gives instructions for name attributes for backwards-compatibility.

In your code you have to add an id attribute to your anchor in template.html:

<a name="myAnchor" id="myAnchor"></a>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM