Skip navigation
Currently Being Moderated

Calling webpages via AJAX while keeping navigation in sight.

Aug 30, 2012 12:10 PM

Hi!

 

I'm wondering if there's an easy way to load a webpage while the navigation bar remains firmly in place (absolute static positioning).

 

I'm assuming this is why AJAX exists.

 

Basically, I've got 20 web pages but they all have the same navigation bar that is always on-screen, always in the same position. I don't want it going anywhere while the browser fetches and displays the targeted web page.

 

If there's a tutorial out there on how to do this, I'd love a link to it.

 

Many thanks in advance.

 
Replies
  • Currently Being Moderated
    Aug 30, 2012 12:50 PM   in reply to jyeager11

    Put a div with a unique id below the navigation.

    Use AJaX to get the HTML of documents and set the innerHTML of the div to that.

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 1:16 PM   in reply to jyeager11

    Have the navigation in a div at the top of the page (I'm assuming horizontal navigation; if it's vertical, float it to the left.)

     

    Underneath that, put a div with nothing in it and give it an id. (div id="contents"></div>).

     

    For each link in the navigation, prevent the default action and call an AJaX function that will "get" the associated document for that link.

    <a href="javascript:void(0);" onclick="ajaxFunctionGet('index.cfm')">Home</a>

    <a href="javascript:void(0);" onclick="ajaxFunctionGet('about.cfm')">About Us</a>

    ...

    <a href="javascript:void(0);" onclick="ajaxFunctionGet('login.cfm')">Login</a>

     

    Write a javascript function that uses AJaX to call the contents of that document.  If you are using jQuery it might be something like:

     

    function ajaxFunctionGet(doc){

      $.get(doc,function(data){ document.getElementById("contents").innerHTML = data; });

      }

     

    This is way oversimplified, but you should get the idea.

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 1:21 PM   in reply to WolfShade

    I just thought of something to add.

     

    On all the documents that will become the innerHTML of the div, remove the doctype declaration, head, and body tags.  Just the content should be presented.  This is assuming that the document that contains the navigation and div for content will already have these things.

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 2:20 PM   in reply to WolfShade

    My only problem with building a site this way is that when JavaScript is disabled, site navigation fails.  Approx. 20% of people turn off scripts in their browsers for perceived security reasons.    Also search engine bots don't use JavaScript, so they won't follow those links.

     

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 2:28 PM   in reply to Nancy O.

    20%?!

     

    Sure you didn't forget a decimal point between the 2 and the 0?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 3:20 PM   in reply to Jon Fritz II

    Whatever number you care to use, it represents a whole lot of people worldwide.

     

    Consider 

    • 2+ million people who use the NoScript add-on for Firefox. 
    • Disabled people with web assisting technologies who can't use JS.
    • Government agencies with restricted access who can't use JS.
    • Public sector organisations who block JS on their networks.
    • Third-world users on very old computers who can't use JS.
    • etc.

     

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 31, 2012 5:39 AM   in reply to WolfShade

    It's NOT the smartest way to do it.  But if you must do something like that, what I've suggested will work.  But, then again, if you really need to do it this way, the smarter option would be (shudder, cringe) FRAMES.

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 31, 2012 1:59 PM   in reply to WolfShade

    It's NOT the smartest way to do it.  But if you must do something like that, what I've suggested will work. 

    Agreed.

     

    if you really need to do it this way, the smarter option would be (shudder, cringe) FRAMES.

     

    Not Frames but an inline frame (iFrame) on the index page would work.    No JavaScript links required.  Each nav link would simply need a target attribute pointing to the iFrame ID:

     

         <a href="page1.html" target="iFrameID">Page 1</a>

         <a href="page2.html" target="iFrameID">Page 2</a>

     

     

     

    Nancy O.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points