I have a page with event listeners for network status. When the network is disconnected, I want to disconnect any cross-domains to go offline. I tried to use .preventDefault(), however, when the application returns to the network, I need to enable links again.
Event listeners
if(!navigator.onLine) {
offlineLinks();
}
window.addEventListener('offline', function(e) {
offlineLinks();
}, false);
window.addEventListener('online', function(e) {
}, false);
window.addEventListener('error', function(e) {
alert('Error fetching manifest: there is a good chance we are offline.');
offlineLinks();
});
Function for 'untie'
function offlineLinks() {
$('a[href^="http"]').click(function(e) {
e.preventDefault();
$('#offline-dialog').dialog({
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
}
}
});
});
}
I am looking for a scalable solution that will not cause a delay if the page has a significant number of links. Is there a simple call handling solution .preventDefault()or a better way to complete this task?
Possible solutions
href, /. HTML5 webdb hrefs onclick... , .