Is there any method to get the URL without query string?

后端 未结 14 1224
天涯浪人
天涯浪人 2020-11-28 19:22

I have a URL like http://localhost/dms/mduserSecurity/UIL/index.php?menu=true&submenu=true&pcode=1235.

I want to get the URL without the query s

相关标签:
14条回答
  • 2020-11-28 19:56

    If you use dot net core 3.1, it is supporting case ignore route, so the previous way is not helpful if the rout is in small letters and the user writes the rout in capital letters.

    So, the following code is very helpful:

    $(document).ready(function () {
        $("div.sidebar nav a").removeClass("active");
        var urlPath = window.location.pathname.split("?")[0];
        var nav = $('div.sidebar nav a').filter(function () {
            return $(this).attr('href').toLowerCase().indexOf(urlPath.toLocaleLowerCase()) > -1;
        });
        $(nav).each(function () {
            if ($(this).attr("href").toLowerCase() == urlPath.toLocaleLowerCase())
                $(this).addClass('active');
        });
    });
    
    0 讨论(0)
  • 2020-11-28 19:58

    just cut the string using split (the easy way):

    var myString = "http://localhost/dms/mduserSecurity/UIL/index.php?menu=true&submenu=true&pcode=1235"
    var mySplitResult = myString.split("?");
    alert(mySplitResult[0]);
    
    0 讨论(0)
提交回复
热议问题