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 7904711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:11:51+00:00 2026-06-03T10:11:51+00:00

We have pretty standard web-site and I got a task to convert links between

  • 0

We have pretty standard web-site and I got a task to convert links between pages to AJAX calls, but maintain direct links (from search engines, for example) working too.

My goals:

  • Leave direct links working as before (and hash fallback for old IE), smooth transition from arriving by direct link and futher browsing using AJAX
  • Implement some “garbage collection” (DOM of previously viewed pages, script handlers etc)

I’ve seen something similar in jQuery Mobile, but I’m looking for more general solution to get inspiration (or borrow code) from 🙂

  • 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-06-03T10:11:58+00:00Added an answer on June 3, 2026 at 10:11 am

    Ok well first you need to be able to separate external and internal links. I wrote the following JQuery selectors for that purpose:

    $.expr[':'].internal = function (obj) {
        return (obj.hostname == location.hostname);
    };
    
    $.expr[':'].external = function (obj) {
        return (obj.hostname != location.hostname);
    };
    

    This lets you select all internal or external links $("a:internal")....

    Next you need to override the click event on all internal links, override the default behaviour grab the Href url and perform an ajax request to the href URL and spit the result into the body

        $("a:internal").click(ajaxLinkHandler);
    
        function ajaxLinkHandler() {
           $.get($(this).attr("href"), function(data) {
           $('body').html(data);
         });
    }
    

    You’ll also need to look at history.js for enabling browser history/back button and address bar updates. You’ll also need to detect AJAX requests on the serverside and return only the <body> or else return everything and change the example above to $("html").html(data).

    You’ll need to handle the onLoad/DOM events or use the new JQuery “On” Handler $(document).on("click", "a", ajaxLinkHandler) That way when the click event bubbles up to the document it will check if it was initiated from an anchor tag, therefore no onReady event required.

    The browser manages DOM garbage collection for you. Open any JQuery page, go to the firebug/chrome dev tool DOM tab and inspect the document. Then go to the console tab and type $(“html”).remove() go back to the DOM tab and you’ll see its been totally cleaned up. You’re calling replace() not remove, so the old DOM elements are replace with the new ones from the AJAX call.

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

Sidebar

Related Questions

My problem: require_once '/includes/aws-sdk-1.5.2/sdk.class.php'; My environment: I have a pretty standard PHP site that
I have some DataGrids with pretty standard one-line itemrenderers, but need to use a
I have what I imagine to be a pretty standard web-interface. There are 4
We have an ASP.NET project (40 or so Web forms, 50 tables, pretty standard
I have pretty standard Qmail toaster installation. I'm using the dot files to set
I have a pretty standard database sitting on SQL Server. To manage the data
I have a pretty standard Repository pattern going, where repositories are injected into my
I have a pretty standard .NET MVC 3 application that uses Ninject for dependency
We have a web application written in ASP.NET for .NET 3.5, using standard web
So, I have at site where I want pages such as; www.example.com/shop/index.php (or any

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.