I want to use dynamic URL update through js script:
window.history.pushState("string", "Title", "/new-url");
But if browser is old and not supporing this function it should simply redirect to new URL.
Is there any simple way to check it ?
I want to use dynamic URL update through js script:
window.history.pushState("string", "Title", "/new-url");
But if browser is old and not supporing this function it should simply redirect to new URL.
Is there any simple way to check it ?
Share Improve this question asked Apr 1, 2014 at 9:10 VololodymyrVololodymyr 2,2886 gold badges31 silver badges53 bronze badges 1- Possible duplicate of: stackoverflow./questions/4966090/can-use-pushstate – witherwind Commented Apr 1, 2014 at 9:16
4 Answers
Reset to default 7You simply check:
if (history.pushState) {
}
The easiest (and most performant):
if ('history' in window && 'pushState' in history) { // available
Still, I'd suggest using some established solutions for history management, like History.js.
try {
window.history.pushState("string", "Title", "/new-url");
} catch ( e ) {
window.location = "/new-url";
}
if(!!history && !!history.pushState){
//browsers which support history and history's push state method
}