Add to URI / URL without refreshing the page using JavaScript / jQuery

I have an MVC framework with which I manipulate the DOM with JavaScript and jQuery. Which to such an extent is a silent reference to this question. Via MVC, if I go to

domain.com/page/

I land on the default page with the latest information, updates, etc. However, through MVC, if I go to something like

domain.com/page/ref1/ref2/ref3

We can cope with the fact that on the backend to do what we want. When he went straight. So, the thought here for this question is whether I can simulate a cross-browser behavior, at least until IE 6/7 +, Firefox 3.x +, Chrome. And by imitation, I mean manipulating the URL / URI as I would the DOM itself. That way, when someone comes in and navigates through the sections using the methods we control the DOM and find what they want to share, all they need to do is go to the browser URL bar and then copy and paste it in the message.

What would be even better is a method that can work with history buttons and forward in browsers. All without having to reload / refresh the page.

+4
source share
2 answers

You tried

window.location.replace(URL) 

This function does not load pages. If you change your current location like this when redirecting there, your last address will be an unmodified address. It does not write the new URL in browser history. Thus, it will look as if you are simply giving the key to what the user wants to share.

+2
source

Have you considered changing the binding in the URL? On this page:

http://www.google.com/

URL change:

http://www.google.com/#foo

... does not activate page refresh. This way you can use (read / modify) the contents of the URL after binding everything you want and the page will not reload. Must be able to use this idea.

+2
source

Source: https://habr.com/ru/post/1383801/


All Articles