Jump to content

Anchor navigation /like facebook


crashmaster

Recommended Posts

[using JQuery]

 

 

Hi there,

 

I am trying to find some plugin, which can make AJAX request's by

parsing ANCHOR value, from URL...

 

For example I have an ajax gallery and I want to make navigation like

this

 

www.example.com/gallery.php#photo=1

www.example.com/gallery.php#photo=2

www.example.com/gallery.php#photo=3

 

Any suggestions ?

Link to comment
Share on other sites

  • 3 months later...

Hello crashmaster, did you ever find anything?

 

If not, try this:

 

a file named callbacks.php, with

<?php 
//Captures the petition and load the suitable section
$file = $_GET['section'];


if(file_exists("$file"))
   {
print("<img src=$abc></img>"); 
  }
else
  {
  die('<title>404 | YOUR_SITE_NAME</title><h1>Ooops...</h1>
<p>You hit a 404: You either have an old bookmark or took a bad link.</p>');
  }

 

Another file named core.js with:

//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
//Function which checks to see if there are any anchor changes, if there are, it sends the ajax petition
function checkAnchor(){
//Check if it has changes
if(currentAnchor != document.location.hash){
	currentAnchor = document.location.hash;
	//if there is not anchor, the loads the default section
	if(!currentAnchor)
		query = "section=home";
	else
	{
		//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
		var splits = currentAnchor.substring(1).split('&');
		//Get the section
		var section = splits[0];
		delete splits[0];
		//Create the params string
		var params = splits.join('&');
		var query = "section=" + section + params;
	}
	//Send the petition
	$.get("callbacks.php",query, function(data){
		$("#content").html(data);
	});
}
}

 

And of course, your index.php file, with:

<head>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript" src="core.js"></script>
</head>
<body>
<a href="#photo.jpg">Photo1</a>
</body>

NOTE: You'll have to download jQuery, and place it in your working directory.

You can also have a link point to a file in a subdirectory, ie: #photos/photo1.png.

 

If you have any questions, speak up. :) ~James

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.