Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove parameter from query string without reloading

Is it possible to remove parameter from query-string with js, I have tried below one unfortunately its works in browser console not in JS file.

 var clean_uri = location.protocol + "//" +       location.host+location.pathname;
 window.history.replaceState({}, document.title, clean_uri);

what would be the best way to do it.

like image 710
naCheex Avatar asked Nov 08 '22 21:11

naCheex


1 Answers

The reason this would only work in the browser is that the window.history API is only available in your browser. I'm not quite sure what you mean by 'from file'. But as one of the commenters pointed out the problem is in the context of where it is executed. If for instance you are executing this in a Node environment rather than a browser, there is no window.history api. Node doesn't even have a window object.

Since you've added an AngularJs flag, it might be that the routing inside the app is listening to changes to the URL and will act on them. Angular may have it's own way of allowing you to change the URL but I'm not familiar enough to help with that.

like image 123
Jake Rowsell Avatar answered Nov 15 '22 06:11

Jake Rowsell