How can I make a page do two different things based on which element’s id is mentioned in the URL? For example, if the URL was website.com/page#id1 the page would do one thing, and if it was website.com/page#id2, it would do another?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both server-side and client-side, the answer is yes.
Server-side, your URL would need to be structured differently than you have, for example:
…or with RESTful routing
The latter can be accomplished with something like Apache’s
mod_rewrite.To access the
idvalue within your PHP code, you would$_GET['id'], and process it appropriately.Client-side, you would need to do this using JavaScript using
location.hashorlocation.href. GitHub does this to great effect with navigable hashing.