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

  • Home
  • SEARCH
  • 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 7574833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:31:59+00:00 2026-05-30T16:31:59+00:00

I have put together some code from various sources but javascript is somewhat unknown

  • 0

I have put together some code from various sources but javascript is somewhat unknown to me and I only seem to fail with the code I have so far..

What I want to do is convert every normal link on the page to ajax links and load the pages through ajax.

So far I only succeeded to transform the links from the initial page and load the content in a div. The problem is I don’t have access to the content is loading in the div and the new content still has normal links instead of ajax.

  • Is there a way I can convert the new links within the content loaded in the div, every time the div changes?
  • Also what I don’t know is, if the user clicks on the home button in the menu, it will load the content of index along with this script, and everything will become a loop. How can I prevent the code from loading in index if it loads inside the div?
  • If you suspect any other problems it may occur from this code can you please advice me what to change?

This is the code I have so far..
Thank you very much for any advice!

Inserted in the head tag:

<script type="text/javascript">
var xmlhttp;
if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else if(window.ActiveXObject){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
else{ }
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4)
{ document.getElementById("contentarea").innerHTML = xmlhttp.responseText; }
else{ document.getElementById("contentarea").innerHTML = ""; }
}

function loadPage(url){
document.getElementById("contentarea").innerHTML = "";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
</script>

Inserted somewhere in the body:

<div id="contentarea"></div>

Inserted right before the body ends:

<script>
var oP = document.getElementsByTagName("a");
var ctr=0;
while(ctr < oP.length){
var oldHref = document.getElementsByTagName("a")[ctr].href;
document.getElementsByTagName("a")[ctr].href="javascript:loadPage('"+oldHref+"');";
ctr++;
}
</script>
  • 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-30T16:32:00+00:00Added an answer on May 30, 2026 at 4:32 pm

    here ja go.. whipped this up for you.. you can use document.links to get all anchor tags. I’m doing this on ‘contentArea’ only. Everything inside (function () { will only be called when the document is ready. Then, in the onreadystatechange event I call the function again to set the click event on any anchors that are returned in the resposne.

    <script type="text/javascript">
    var xmlhttp;
    
    function loadPage(url){
    document.getElementById("contentarea").innerHTML = "";
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
    var parseAnchors = function(){
        var anchors = document.getElementById("contentarea").links; // your anchor collection
        var i = anchors.length;
        while (i--) {
          var anchor = anchors[i];
            anchor.onclick = (function(url) {
              return function() {
                loadPage(url);
                return false;
              };
            })(anchors[i].href);
            anchor.href = "#";
        }
      };
    
    (function () {
    
    if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
       else if(window.ActiveXObject){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
       else{ }
       xmlhttp.onreadystatechange=function(){
       if(xmlhttp.readyState==4)
       { document.getElementById("contentarea").innerHTML = xmlhttp.responseText; }
       else{ document.getElementById("contentarea").innerHTML = ""; }
       parseAnchors();
     }
    
    window.onload = function () {
     parseAnchors();
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with the example code from the ExecutorCompletionService and put together
I have MANY small Test Projects where I put together just enough code to
I have 2 blocks of code, if someone could help me put them together
i have some code that looks like this and creates a list from an
I have some functions that can be grouped together, but don't belong to some
I have an HttpModule that I have put together from cobbling a couple of
Forgive me coder for I have sinned. I put some code into a dll
I put together some VBA code for Outlook 2007 which has been working predominantly
I've got some code that uses the regular Forms API to put together a
I put together a download script after some wonderful help from stack overflow the

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.