Window.location Java Script/JQuery/PHP issue
I have added a couple of new pages and included the menu box on the left, entitled left_menu.php. However when clicking on a category title from the 2 new pages I don't get sent to the right category or any.
I have included the J/Query Javascript code and still no joy. I have noticed the window.location is set to window.location.hash = (followed by query string)but this only works on the original page which had the menu /categories.php. An example would be http://isenterprises.co.uk/category#3:any:any:1: '3' been the category.
On my two new pages, /search_results.php and /singleproduct.php, /search_results?#3:any:any:1: and /singleproduct.php?#3:any:any:1: does not work. I have tried, window.location to window.location.href ("/categories.php") = (followed by query string). But this does not work either.
Is there a way to make the 2 new pages show the results required by simply changing the window.location destination or can some one please come up a simple alternative? I have included the script below.
A
<script type="text/javascript">
(function($) {
$.fn.stripHtml = function() {
var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
this.each(function() {
$(this).html(
$(this).html().replace(regexp,"")
);
});
return $(this);
}
})(jQuery);
$(function(){
$.preloadImages = function()
{
for(var i = 0; i<arguments.length; i++)
{
jQuery("<img>").attr("src", arguments[i]);
}
}
$.preloadImages("/images/loading.gif");
var sProduct = "";
var sBrand = "";
var sCategory = "";
var sPage = "";
var sSearch = "";
var split_address = Array;
split_address[0] = "any";
split_address[1] = "any";
split_address[2] = "any";
split_address[3] = 1;
split_address[4] = "";
var address = window.location.hash;
if ( address != "" )
{
address = address.replace(/^#*/i, "");
address = address.replace(/%20/g, " ");
split_address = address.split(":");
// Call other function here and send it the inputs inside the split_address array
}
if ((split_address[0] != "" && split_address[1] != "" && split_address[2] != || split_address[4] != "") {
sProduct = split_address[0];
$(".product ." + sProduct).addClas开发者_StackOverflow中文版s("selected");
sBrand = split_address[1];
$(".brand ." + sBrand).addClass("selected");
sCategory = split_address[2];
sPage = split_address[3];
sSearch = split_address[4];
loadQuery();
}
$('#left_menu ul li a').click(function(e){
e.preventDefault();
});
$('#pagination_box a').live("click", function(e){
e.preventDefault();
});
$('#pagination_box #prev').live("click", function(){
$(this).live("click",function(){
return false;
});
sPage--;
window.location.hash = sProduct + ":" + sBrand + ":" + sCategory +":" + sPage + ":" + sSearch;
loadQuery();
});
$('#pagination_box #next').live("click", function(){
$(this).live("click",function(){
return false;
});
sPage++;
window.location.hash = sProduct + ":" + sBrand + ":" + sCategory + ":" + sPage + ":" + sSearch;
loadQuery();
});
$('#pagination_box #page').live("click", function(){
$(this).live("click",function(){
return false;
});
newsPage = $(this).stripHtml();
sPage = newsPage.html()
window.location.hash = sProduct + ":" + sBrand + ":" + sCategory + ":" +
loadQuery();
});
function loadQuery() {
$('#content').html("<br /><br /><br /><center><img src=\"/images /loading.gif\" alt=\"loading\"/><br /><p>Please wait...</p></center>");
$.get("/serv_category.php", { product: sProduct, brand: sBrand, category: sCategory, page: sPage, search: sSearch },
function(data,status){
$('#content').html(data);
});
}
$('#searchinput').live("keyup", function(e) {
if(e.keyCode == 13) {
sSearch = $('#searchinput').val();
window.location.hash = sProduct + ":" + sBrand + ":" + sCategory + ":" + sPage + ":" + sSearch;
loadQuery();
}
});
$('#left_menu ul li').click(function(){
$(this).click(function(){
return false;
});
if ($(this).attr('class') != "title") {
if ($(this).parent().attr('class') == "product") {
if ($(this).attr('class') != "all") {
oldsProduct = sProduct;
$(".product ." + oldsProduct).removeClass("selected"); sProduct = $(this).attr('class');
$(this).addClass("selected");
} else {
oldsProduct = sProduct;
$(".product ." + oldsProduct).removeClass("selected");
sProduct = $(this).attr('class');
sProduct = "any";
}
}
if ($(this).parent().attr('class') == "brand") {
if ($(this).attr('class') != "all") {
oldsBrand = sBrand;
$(".brand ." + oldsBrand).removeClass("selected");
sBrand = $(this).attr('class');
$(this).addClass("selected");
} else {
oldsBrand = sBrand;
$(".brand ." + oldsBrand).removeClass("selected");
sBrand = $(this).attr('class');
sBrand = "any";
}
}
if ($(this).parent().attr('class') == "category") {
if ($(this).attr('class') != "all") {
sCategory = $(this).attr('class');
$(this).addClass("selected");
} else {
sCategory = "any";
}
}
sPage=1;
window.location.hash = sProduct + ":" + sBrand + ":" + sCategory + ":" + sPage + ":" + sSearch;
loadQuery();
};
});
});
Have you tried something with Jquery Address? Look this: http://www.asual.com/jquery/address
精彩评论