Jump to content

[SOLVED] jQuery History Help


chordsoflife

Recommended Posts

I'm really struggling with this, mostly because I don't know JS very well. If anyone can tell me anything to lead me in the right direction, it would mean the world. Here's the code:

 

function pageload(hash)	{

alert("function ran");

	if(hash) {
		alert("function true");
		$(".page01").hide();
		$(".page02").hide();
		$(".page03").hide();
		//$("." + hash + "").show();
	} else {
		alert("function false");
		$(".page01").hide();
		$(".page02").hide();
		$(".page03").hide();
	}

}

$(document).ready(function(){

	$.history.init(pageload);

	$("a[@rel='history']").click(function(){

		var hash = this.href;
		hash = hash.replace(/^.*#/, '');

		alert(hash);

	});
});

 

It should be pretty clear what I'm trying to do (and alerts to see if I can figure out what's happening when), but I'll explain:

 

I have three divs on a page, and up top there's a navigation (page 1 2 3). Each link hides two and shows only one page. Each page has about ten links to other pages. When I click to an individual page, I want to be able to click the browsers back button back to whichever "page" (1, 2 or 3) I was on.

 

Thanks!

Link to comment
Share on other sites

Hm. I actually figured it out on my own (+1 for life). Here's what I wound up doing in case anyone is interested.. not extremely versatile though.

 

$(document).ready(function(){

	function pageload(hash)	{

		$(".page01").hide();
		$(".page02").hide();
		$(".page03").hide();

		if(hash) {
			$(".page0" + hash + "").fadeIn();
		} else {
			alert("else.");
			$(".page01").fadeIn();
		}
	}	

	$(".page02").hide();
	$(".page03").hide();

	$.historyInit(pageload);

});

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.