How to remove the hash from [removed] (URL) with JavaScript without page refresh?

前端 未结 16 3034
无人及你
无人及你 2020-11-22 02:53

I have URL like: http://example.com#something, how do I remove #something, without causing the page to refresh?

I attempted the following

16条回答
  •  广开言路
    2020-11-22 03:06

    To remove the hash, you may try using this function

    function remove_hash_from_url()
    {
        var uri = window.location.toString();
        if (uri.indexOf("#") > 0) {
            var clean_uri = uri.substring(0, uri.indexOf("#"));
            window.history.replaceState({}, document.title, clean_uri);
        }
    }
    

提交回复
热议问题