How to pass GET parameters and use # to go to part of my page?

So, I am developing a mobile web application, and at some point I have the following:

<a href="index.php?key=blabla#detailsDepense"> 

It almost does what it intended, it goes to index.php and goes to the detailDepense section. Unfortunately, it just discards the GET key parameter from the URL and makes it inaccessible with php.

How to pass GET parameters when using a hash (#) in my URL?

+4
source share
1 answer

Format the pseudo hash in your query string as a GET variable ...

 <a href="index.php?key=blabla&hash=etailsDepense"> 

Then, on your page, pass this location.hash variable using PHP / JavaScript:

 <script type="text/javascript"> <?php if ($_GET['hash']) { ?> location.hash = <?php echo "'".$_GET['hash']."';"; } ?> </script> 

Just like that!

+3
source

Source: https://habr.com/ru/post/1384198/


All Articles