Detect what page you are on JavaScript?

This question already has an answer here:

  • Get the current URL with JavaScript? 18 answers

  • document.URL will get you the URL of the current page.

    To check for a specific page you would use:

    if ( document.URL.contains("homepage.aspx") ) {
        //Code here
    }
    

    Get url of page are you on

    location.href
    

    Or

    document.URL
    

    Set style to element by id:

    document.getElementById('mydiv').style.border = '1px solid black';
    
    链接地址: http://www.djcxy.com/p/22536.html

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

    下一篇: 检测你在JavaScript上的页面?