I'm wondering if Javascript can detect what page the user is on. Say for example that the user is on a "About" or "Contact" page, can JavaScript check if the pathway is "/About" or "/Contact" and then take action accordingly ? How would that code look like? I appreciate if anyone could give me a code sample
2 Answers
If you want to know what age they are on, it really depends on the url structure. But you will get the information with window.location.pathname
var pathname = window.location.pathname;
switch(pathname) {
case "/home" :
console.log("home");
break;
case "/game" :
console.log("game");
break;
}
document.location.href.if(location.href=='/contacts')document.body.innerHTML="";check the location, set the body html to empty string.