简体   繁体   English

PHP标头位置-使用HTML锚点重定向到URL

[英]PHP Header Location - redirect to URL with HTML anchor

I have a website, where after submission of a form user is redirected throught Header Location to the same page but with anchor to fill in another form. 我有一个网站,在提交表单后,用户将通过“页眉位置”重定向到同一页面,但使用锚点来填充另一个表单。

Header('Location: http://www.topdodavatel.cz/tuzby/tuzby.php#nechaj');

However, when the first form is submitted, the user is not landed on the anchored DIV, but on the bottom of page. 但是,提交第一个表单时,用户不会落在锚定的DIV上,而是落在页面底部。

As you can try on development version http://www.topdodavatel.cz/tuzby/tuzby.php 您可以尝试开发版本http://www.topdodavatel.cz/tuzby/tuzby.php

What could cause that the anchor does not work? 是什么原因导致锚不起作用? If I choose some div that is written in the code above, it works well. 如果我选择上面代码中编写的div,则效果很好。

Kindly thank you for your inputs! 谢谢您的投入!

This is a common problem it seems, see here or here for a similar problem. 看来这是一个常见问题,有关类似问题,请参见此处此处

It seems that something along the way, PHP, Apache or your browser strips out the anchor element on redirection. 似乎在进行某些操作时,PHP,Apache或您的浏览器会在重定向时去除锚元素。

To make this work I would suggest moving the anchor content nechaj into a query variable tuzby.php?anchor=nechaj . 为了完成这项工作,我建议将锚定内容nechaj移到查询变量tuzby.php?anchor=nechaj Then in PHP check for this variable and if it exists use JavaScript to move the user to the correct point. 然后在PHP中检查此变量,如果存在,则使用JavaScript将用户移至正确的位置。 Like this: 像这样:

window.location.hash='<?php echo $_GET["anchor"] ?>';

You'll need to add some kind of input verification check for the anchor variable of course. 当然,您需要为anchor变量添加某种输入验证检查。

Name is important 名字很重要

Give submit button like this 给这样的提交按钮

<input type="submit" name="submits" value="Done" />

in the submit box name is required need to submit the form 在提交框中输入名称是必需的,需要提交表格

Provide name in your submit in your site check out it will work 在您的网站提交中提供姓名,请检查一下是否可以使用

Thank everyone for your initiative. 感谢大家的主动。 It showed up that major issue was with DIV that obtained content generated from database and did not have set fixed height, which caused temporary overflow of that DIV. 结果表明,DIV的主要问题是从数据库获取内容并且未设置固定高度,这导致该DIV暂时溢出。

So I fixed it by setting a height to the element and overflow:hidden (before the style loads properly). 因此,我通过将元素的高度设置为overflow:hidden(在样式正确加载之前)来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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