5

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.

2
  • If it works in the console but not in your JS then the problem likely have something to do with the code around what you have shared with us. Commented Jan 22, 2016 at 13:10
  • What do you mean by "not in JS file" -- is it an external JS file you are calling from the page? Commented Jan 23, 2016 at 0:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.