Retrieving data after the hashmark in the query string is simple. Here is an example used when a customer accesses a glossary of terms from a book. It takes the name of the anchor delivered (#tesla), and delivers the term to the client and highlights the term and its description in blue, so it is easy to see.
but. adjust your lines with div id, so the name anchor goes where it is supposed to, and javascript can change text colors
<div id="tesla">Tesla</div> <div id="tesla1">An energy company</div>
C. Use Javascript to do the hard work on the server side inserted in a PHP page, or wherever you are.
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
C. I run the java function automatically when the page loads.
<script> $( document ).ready(function() {
D. get the binding (#tesla) from the URL received by the server
var myhash1 = $(location).attr('hash');
E. trim the hash sign from it
myhash1 = myhash1.substr(1) //myhash1 == tesla
F. I need to highlight the term and description, so I create a new var
var myhash2 = '1'; myhash2 = myhash1.concat(myhash2);
G. Now I can manipulate the text color for the term and description
var elem = document.getElementById(myhash1); elem.style.color = 'blue'; elem = document.getElementById(myhash2); elem.style.color = 'blue'; }); </script>
N. It works. the client clicks on the client side link (xyz.com # tesla) and matches the term. The term and description are highlighted in blue javascript for quick reading. all other entries remained black ..
JamesAD-0 Feb 05 '17 at 2:13 on 2017-02-05 02:13
source share