This function disables the default action for a link, and changes the URL using the pushState function. I need to be able to detect if a browser does not support this function, so that I can stop the preventDefault() function.
$("a").click(function(event) {
var url = "";
var url = $(this).attr('href');
// Disable Default Action and Change the URL -
event.preventDefault();
window.history.pushState("somedata", "Title", url);
//Call Function to change the content -
loadContent(url);
});
Any recommendations are greatly appreciated
Use feature detection:
if (history.pushState) {
// supported.
}
Example:
$("a").click(function(event) {
var url = "";
var url = $(this).attr('href');
if (history.pushState) {
window.history.pushState("somedata", "Title", url);
event.preventDefault();
}
//Call Function to change the content -
loadContent(url);
});
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