Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:06:19+00:00 2026-05-23T05:06:19+00:00

I have a page that has event listeners for the network status. When the

  • 0

I have a page that has event listeners for the network status. When the network is ‘offline’ I want to disable any cross domain links as to go into an offline mode. I was trying to use .preventDefault(), however when the app comes back online I need to re-enable the links.

Event Listeners

//check network status
if(!navigator.onLine) { 
    offlineLinks(); //Offline mode function
}
//add event listeners for network status
window.addEventListener('offline', function(e) {
    offlineLinks(); //Offline mode function
}, false);
window.addEventListener('online', function(e) {
    //need to re-enable links/Online mode
}, false);
window.addEventListener('error', function(e) {
    alert('Error fetching manifest: there is a good chance we are offline.');
    offlineLinks(); //Offline mode function
});

Function for ‘de-linking’

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 won’t cause lag if there are significant numbers of links on the page. Is there a simple solution to reverse the .preventDefault() call or a better way to accomplish this task?

Possible Solutions


My initial thoughts were either having store an array of the href values and then remove/add. I have been playing around with the HTML5 storage using webdb‘s I could create a database for and dynamically pull the hrefs onclick…however I’m not sure if this is the best solution for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:06:19+00:00Added an answer on May 23, 2026 at 5:06 am

    You seem to be using jQuery, at least for the link handler part.

    The thing to realize is that $.click(handler) is just shorthand for .bind(‘click’, handler). If you define the handler elsewhere, you can also unbind it later, like this:

    var handler = function(event) { 
      event.preventDefault();
      console.log("the links, they do nothing!");
    }
    
    // when you want the external links to be inactive.
    // you could use .click(handler) here too, it's the same.
    $('a[href^="http"]').bind('click', handler);
    
    // when you want them back
    $('a[href^="http"]').unbind('click', handler);
    

    By the way, href^=”http” is a bit fragile, if you only want this to happen to external links. Internal links might start with “http”, and some external links could start with other protocols like “ftp”. Better to give such links their own class, like Wikipedia does with ‘external’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with php and want to have a page that has a
I have a page that has multiple selectors. Each has an on click event.
I have a textbox in an aspx page that has a TextChanged event attached
I have a page that has an iframe From one of the pages within
I have a Page that has a single instance of a UserControl that itself
I have a page that has fields dynamically loaded via JQuery. It allows a
I have a page that has 2 columns of words, 20 total, that are
I have a page that has a bunch of user controls on it. I
I have a page that has a large image on it with a number
I have a page that has several ajax submission forms. Each form has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.