AJAXify your Website


Revision as of 10:34, 16 November 2010 by Dinsley (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You can AJAXify your website builder site, or make all of your pages load via AJAX by adding some simple JavaScript code utilizing the built in jQuery.


Since the main content area of website builder is inside a div#location_0, all you have to do is hook into the Primary Navigation links and use the jQuery load function to replace the contents of #location_0 on the current page with the contents of #location_0 on the target page. Adding a slideUp/slideDown with some callbacks makes it have a nice transition as well.

Adding to your Site

In order to add this code to your website's source code, you'll need to follow the directions below:


1. Go to the My Website toolbar menu, and click on Edit Theme Source Code.
2. Click on the default.html in the table that lists your theme files.
3. Add the following code below code inside of the <head> element:


<script type="text/javascript">
$j('#primary_navigation li a').click(function() { loadPage( $j(this).attr('href')); return false; });

function loadPage( page ) { 
  $j('#location_0').slideUp(300, function() { 
    $j('#location_0').load( page + ' #location_0 > *', function() { $j('#location_0').slideDown(300);}); 
  });
}
</script>

Example Sites

http://showcase.imyuao.com/