With window.history.pushState
it is possible to push a state to the browser's history.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="button" value="foo" onclick="setHistory('foo');">
<input type="button" value="bar" onclick="setHistory('bar');">
<script>
function setHistory(string) {
document.title = string;
window.history.pushState(
'object or string',
'',
string+'.html'
);
}
</script>
</body>
</html>
After clicking on the foo and bar button the responding entries will appear in the browser's history. This works in Firefox, Chrome, and Safari. However, not in IE (>10) and Edge even though they officially support it. Is there a way to achieve this?
The answers at Does Internet Explorer support pushState and replaceState? are not useful since they explain the problem only with IE<10 where pushState
is not supported.
Edit
Apart from not updating the history, pushState
seems works otherwise fine in IE and Edge, i.e. updates the URL, can navigate back and forth, the "back and forth drop down list" is updated accordingly.
Edit 2
I just read https://msdn.microsoft.com/en-us/library/ms535864(v=vs.85).aspx. Under "Remarks" it states
"For security reasons, the history object does not expose the actual URLs in the browser history."
So maybe the part of pushState
I am after just isn't supported in IE and Edge?