jNavigate jQuery Plugin

Posted on April 12, 2011 by Phil   28 comments

This plugin has had a rewrite and can now be found at the official jNavigate website

I started building this plugin a while back when I wanted to replicate some of the nicer features of ColdFusion’s CFajax library such as the connection between a CFForm and it’s parent CFDiv where the CFForm submits and loads back into the CFDiv via ajax. If any of you are familiar with the ColdFusion implemetation of this then you are also probably aware of just how crap it is with all sorts of JavaScript files being added to your page header and mindless attributes spread all around your HTML page.

I knocked together this jQuery version of the aforementioned functionality and recently added in some support for history states. While still a work in progress it certainly has enough in it already to pick up and use whether that be to enable a single page brochure site, submit a newsletter sign up form or to just populate a small content box. You can check out the little demo/documentation site I put together using jNavigate to get an idea of how it works.

28 Responses So Far

  1. Pingback: Download jNavigate | Free Web Script

  2. Nixon Girard April 25, 2011 at 2:34 am

    How do I make an autoload using your plugin?

  3. Turnthefire May 18, 2011 at 5:11 pm

    I’m having trouble with the anchor and submit button, if I use href=”index?page=main” then comes up the hole index page in the main div!? Wat I’m doing wrong? how to setup the script?

    • Phil May 18, 2011 at 7:35 pm

      You’d need to check for the jnavigate flag in the query string and return only the content needed. For example:


      if (!array_key_exists('jnavigate', $_GET) ) : // show header/footer or whatever
      // show content

  4. Turnthefire May 18, 2011 at 8:56 pm

    I don’t get it, my page looks somthing like this:


    html
    head
    body

    include(header);

    if(isset($_GET["page"]))
    {
    echo $_GET["page"]".php";
    }

    include(footer);

    body
    html

    I’m รก little bit newbie to this kind of stuff… But how can I prevent not loading the whole website in the main div?

    • Phil May 19, 2011 at 12:35 pm

      Ok so what you would need to do is separate what content you need to return based on the jnavigate flag.


      if !array_key_exists('jnavigate', $_GET) :
      html
      head
      body

      include(header);

      endif;

      if(isset($_GET["page"]))
      {
      echo $_GET["page"]".php";
      }

      if !array_key_exists('jnavigate', $_GET) :

      include(footer);

      body
      html

      endif;

  5. Turnthefire May 19, 2011 at 2:52 pm

    alright great, it works fine now.

    But I’m having some trouble in IE7 and 8. IE9 works fine. in 7 and 8 the main does not show up. and in none of the IE browser is the browser-address “index.php?page=main” showing.
    any advise?

    btw. great plugin

  6. Phil May 19, 2011 at 9:27 pm

    Should show up OK in IE?

    The URL, IE (not even 9 AFAIKR) does not support the new History API.

    Thanks

  7. Turnthefire May 22, 2011 at 2:47 pm

    hmmm, not for me in IE7 and IE8, IE9 works fine… , I use exactly the script you have written above..??

  8. David June 30, 2011 at 9:27 pm

    Help me out please! I seem to have a bit of a problem like Turnthefire’s orginal post. I was dealing with the whole page appearing in the main div. Right now I have an “unexpected end” error.

    Bare with me, Im a newbie to PHP. My code looks something like this:

    html
    body

    main content div
    scripts

    body
    html

  9. David June 30, 2011 at 9:30 pm

    Oops, here is my code again:

    ?php
    include(“nav.php”);
    ?
    ?php
    if(isset($_GET["page"])) {
    if(file_exists(“pages/”.$_GET["page"].”.php”)) {
    include(“pages/”.$_GET["page"].”.php”);
    }
    else {
    echo(“Page not found.”);
    exit;
    if (array_key_exists(“jNavigate”,$_GET["page"]))
    ?

    • Phil June 30, 2011 at 10:42 pm

      From what I can see of your code the line; if (array_key_exists("jNavigate",$_GET["page"]) should just be if (array_key_exists("jNavigate",$_GET).

  10. David July 3, 2011 at 8:09 pm

    Thanks for the last post, for some reason I still am having problems getting it to work. Right now, the page turns up blank. Im think the array key exists is returning false, though I could easily be wrong. Here is my code. I have the html, css, and scripts before the php on my index.php file. My main.php includes my nav and closing divs for body and html. Any guess what’s wrong Phil?

    //

  11. David July 3, 2011 at 8:10 pm

    ?php
    if (array_key_exists(“jNavigate”, $_GET)):
    include (“main.php”);
    endif;
    if (isset($_GET["page"]))
    {
    include(“pages/”.$_GET["page"].”.php”);
    }
    if (array_key_exists(“jNavigate”, $_GET)):
    endif;
    ?

  12. Phil July 4, 2011 at 8:37 pm

    Again it’s hard to tell from the code you posted but jnavigate should be all lower case. If you only wish to pull in the page.php section you should be negating the check for jnavigate also i.e. if (!array_key_exists…

  13. David July 5, 2011 at 7:51 pm

    Works now thank God! Thanks for your help Phil!

  14. David July 6, 2011 at 9:11 pm

    Hey Phil, any idea why when using Google Chrome the links will not work after the first initial click? from my index page, I can navigate to any page, but after that the links stop.

    When I use Firefox I have no problem. The only thing I cannot get to work yet on any browser is a javascript slider within the main content.

    David

  15. Dev August 19, 2011 at 11:49 am

    Hi,

    Really nice plugin. Exactly what I was looking for. But I can’t get it work properly. Could you please provide the php code too please?

  16. Dev August 20, 2011 at 4:46 pm

    Thanks Phil. Am a PHP/jQuery/HTML newbie and this would help me a lot.

  17. Dev August 20, 2011 at 6:08 pm

    Thanks Phil. Appreciate it.

  18. Pingback: Have You Seen These 30 Ajax Plugins Before? | RockingCode

  19. Pingback: Have You Seen These 30 Ajax Plugins Before? | Web Help 101

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recommended reading

  • Ben Nadel Articles on “obsessively thorough web development” with Coldfusion and jQuery
  • Christian Heimann's blog – Wait till I come!! Articles on web development
  • David Walsh Articles around PHP, CSS, MooTools, jQuery and just about everything else
  • John Resig Javascript programmer and the creator of the jQuery library
  • Mary Lou (Codrops) Stunning designs with lots of cool jQuery effects

Photostream

  • Loading photostream from Flickr...