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
https://forums.phpfreaks.com/topic/166399-solved-jquery-history-help/
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);

});

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.