Remove everything after domain and http in url javascript

This question already has an answer here:

  • Get current URL in JavaScript? 29 answers

  • You can try this:

    //([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#)

    Regex live here.


    Live JavaScript sample:

    var regex = ///([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#)/g;
    
    var input = "https://www.google.com/hello/hi.php, http://youtube.com,"
              + "http://test.net#jump or http://google.com?q=test";
    
    while (match = regex.exec(input)) {
        document.write(match[1] + "<br/>");
    };

    使用全局的window.location.hostname变量,它会给你这个信息。

    链接地址: http://www.djcxy.com/p/70232.html

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

    下一篇: 删除javascript和url中的域和http之后的所有内容