[英]navigate to php page and scroll
My boss asked something very specific: a page.php that will take one argument, and display text based on that argument + when the page is displayed scroll to an anchor on the page based on that argument. 我的老板问了一个非常具体的问题:一个page.php,它将接受一个参数,并在显示该页面时显示基于该参数的文本+滚动到基于该参数的页面锚点。
How is that possible. 那怎么可能。 If I use argument ?a=1 the php can handle it, but how can the browser/javascript? 如果我使用参数?a = 1,php可以处理它,但是浏览器/ javascript如何处理? If I use anchor #a1 the browser can handle it, but I was unable to read this with php. 如果我使用锚点#a1,则浏览器可以处理它,但是我无法使用php读取它。 I used: 我用了:
$_SERVER["REQUEST_URI"]
Any creative solutions to this problem? 对这个问题有什么创造性的解决方案吗?
This is one solution for it. 这是一种解决方案。 If it could not be useful, tell me to give another solution to you. 如果它没有用,请告诉我给您另一个解决方案。
$_GET[""]
使用$_GET[""]
将传递的项目的值读取到URL <?php
if (isset($_GET['a'])) {
$a = $_GET['a'];
$anchor = '#'.$a;
echo('
<script type="javascript">window.location.href="'.$anchor.'"</script>
');
}
?>
Don't forget that you can combine a server-side programming language with a client-side one. 不要忘记,您可以将服务器端编程语言与客户端相结合。 I hope you can solve this issue. 希望您能解决这个问题。 Otherwise, comment this post. 否则,请对此帖子发表评论。
window.location.search
The window.location object contains what you need. window.location对象包含您所需要的。 cf. cf. this: http://davidwalsh.name/javascript-window-location 这个: http : //davidwalsh.name/javascript-window-location
The Hash is not seen by PHP, because the browsers don't send it to the server. PHP无法看到哈希,因为浏览器不会将哈希发送到服务器。 They are normally used the jump to a specific location in the page. 通常用于跳转到页面中的特定位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.