Reputation: 15984
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.
How is that possible. If I use argument ?a=1 the php can handle it, but how can the browser/javascript? If I use anchor #a1 the browser can handle it, but I was unable to read this with php. I used:
$_SERVER["REQUEST_URI"]
Any creative solutions to this problem?
Upvotes: 0
Views: 520
Reputation: 13166
This is one solution for it. If it could not be useful, tell me to give another solution to you.
$_GET[""]
<?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.
Upvotes: 1
Reputation: 32701
window.location.search
The window.location object contains what you need. cf. this: http://davidwalsh.name/javascript-window-location
The Hash is not seen by PHP, because the browsers don't send it to the server. They are normally used the jump to a specific location in the page.
Upvotes: 0