var data = { url: $(this).attr('href'), selector: $(this) };
history.pushState(data, 'foo', $(this).attr('href'));
When I do this I get a error:
Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIDOMHistory.pushState]
If I change selector to a string, then the error goes away... But I need the jQuery object, so I can trigger click on it on the "popstate" event :s
In an HTML document, the history. pushState() method adds an entry to the browser's session history stack.
pushState() method # The history. pushState() method can be used to push a new entry into the browser's history—and as a result, update the displayed URL—without refreshing the page.
The History. replaceState() method modifies the current history entry, replacing it with the state object and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.
The data in the history state must be serializable. That is, it must be convertible to JSON. $(this)
returns an array-like object with DOM nodes which cannot be converted to JSON. You should look for a different way to do what you're looking for.
Remember, the push state is just helpful information and is not meant to be canonical. If the user can't get the exact same content by copying and pasting the URL in the address bar you've got a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With