Detect current page with JavaScript

This question already has an answer here:

  • Get current URL in JavaScript? 29 answers

  • 例如,您可以通过执行以下操作来获取URL:

    window.location.href
    

    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;
    }
    
    链接地址: http://www.djcxy.com/p/70234.html

    上一篇: 如何使用JavaScript获取当前网址?

    下一篇: 使用JavaScript检测当前页面