Here is my current code which does redirecting:
window.location.href= '/post/' + data.main_id + '/' + subject + '#post-' + data.post_id;
Code above just changes the slug when I'm in the same URL. anyway, I need to both change the slug and reload the page. How can I do that by JS or even jQuery?
Here is my current code which does redirecting:
window.location.href= '/post/' + data.main_id + '/' + subject + '#post-' + data.post_id;
Code above just changes the slug when I'm in the same URL. anyway, I need to both change the slug and reload the page. How can I do that by JS or even jQuery?
Share Improve this question asked Dec 22, 2016 at 11:38 Martin AJMartin AJ 6,70712 gold badges71 silver badges137 bronze badges2 Answers
Reset to default 6You can achieve this by first appending the fragment to the URL, then reloading the page:
window.location.href += '#post-' + data.post_id;
window.location.reload();
Note however that you could improve this further by using pushState and avoiding the need to reload the page at all when the fragment changes.
You can use
location.reload();
Please, see http://www.w3schools./jsref/met_loc_reload.asp