M
M
makecode2011-04-04 11:38:05
JavaScript
makecode, 2011-04-04 11:38:05

Change URL without reloading the page?

Hello.
I found that while scrolling through photos in VKontakte with arrows, the URL in the address bar changes. This does not reload the page. Firebug shows that only photos are pulled and that's it. Only works in latest Chrome and Firefox. In other browsers, the link is obtained with a hash (#).
location.hash is clear that you can change without reloading the page, but how is the complete change of the URL implemented in this case? After all, location.href does not allow you to change the URL without reloading.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
S
siegerstein, 2014-11-13
@siegerstein

history.pushState(null, null, '/anypath');

S
sajgak, 2011-04-04
@sajgak

var setLoc = function(loc) {
//curLoc = fixEncode(loc.replace(/#(\/|!)?/, ''));
curLoc = fixEncode(loc);
var l = (location.toString().match(/#(.*)/) || {})[1] || '';
if (!l && vk.al > 1) {
l = (location.pathname || '') + (location.search || '');
}
l = fixEncode(l);
if (l.replace(/^(\/|!)/, '') != curLoc) {
if (vk.al == 3) {
try {
history.pushState({}, '', '/' + curLoc);
return;
} catch(e) {}
}
window.chHashFlag = true;
location.hash = '#' + vk.navPrefix + curLoc;
if (withFrame && getLoc() != curLoc) {
setFrameContent(curLoc);
}
}
}

Pulled out by fireBug from VK. so you are wrong)

M
MastaEx, 2011-04-04
@MastaEx

Yes, it works in Chrome too.
Here, I googled it: www.w3.org/TR/html5/author/history.html#session-history-entry

M
Melanitsky, 2011-04-04
@Melanitsky

why not, you can:
window.location.href=/qa/6436/#photo"
if there is # in the url and the url itself matches, there will be no reload

A
AlexAdmiral, 2011-06-14
@AlexAdmiral

pjax as a good alternative.

K
Konstantin Romanov, 2016-03-09
@evanto

Perhaps this option is suitable
diveintohtml5.info/examples/history/gallery/casey.html
here for more details htmlbook.ru/html5/history

E
Emir Mamashov, 2016-12-30
@EmirMamashov

https://github.com/devote/HTML5-History-API

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question