Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:50:57+00:00 2026-05-27T02:50:57+00:00

I am using jquery + the hashchange plugin from ben alman. Below is a

  • 0

I am using jquery + the hashchange plugin from ben alman. Below is a standard way to grab the hash name and load in content

$(window).hashchange(function() {
var hash = location.hash;
var array_url = hash.split('#');
var page = $(array_url).last()[0];
$('#content').load( page + '.php', function(){
});
});

But is there any way to do this by grabbing some other variable assigned on a click function or sorted through php, perhaps?

I am working with a multi-artist portfolio site that hands out unique three-four letter codes to images

I’d like to serve these images up through unique urls. This has to be through ajax for many reasons.

I had difficulty adding other ajax history options because this page is already using ajax pagination (to load this content) and lots of htaccess url modrewrites.

I am thinking this might just be impossible.

Here is my current code

$('a.photo').click(function () {
    var url = $(this).attr('href'),
    image = new Image();
    image.src = url;
    var clickedLink = $(this).attr('id');
    location.hash = clickedLink;
    image.onload = function () {
         $('#content').empty().append(image);
    };
    image.onerror = function () {
       $('#content').empty().html('That image is not available.');
    }
    $('#content').empty().html('Loading...');
    return false;
});

$(window).hashchange( function(){
    var hash = location.hash;
    var url = ( hash.replace( /^#/, '' ) || 'blank' );
    document.title = url;
})

$(window).hashchange();

and my html / php :

$thethumb = customuniqueidfunc();

<a href="[IMG URL]" 
class="photo gotdesc nohover" rel="<?php echo $row['description'] ?>" 
id="<?php echo $thethumb; ?>">

This works insofar as the image from the href attr loads into the #content div and the hash from the id attr is added as a hash to the url and to the title of the page, but I am lacking any mechanism to combine the click and the hashchange function, so that each hash actually corresponds to the image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:50:57+00:00Added an answer on May 27, 2026 at 2:50 am

    One method I’ve used for this before is to run a hash polling function. You can see it in action at this page:

    http://www.webskethio.com/#services

    Here is the javascript for that page:

    http://www.webskethio.com/ws.js

    Relevant code:

    function pollHash() {
    
        //exit function if hash hasn't changed since last check
        if (window.location.hash==recentHash) {
            return; 
        }
        //hash has changed, update recentHash for future checks 
        recentHash = window.location.hash;
    
        //run AJAX to update page using page identfier from hash 
        initializeFromUrl(recentHash.substr(1));
    
    }
    
    $(document).ready(function(){
    
        /* code removed for readability */ 
    
        setInterval('pollHash()',100); // Important piece
    
        /* code removed for readability */
    
    
    });
    

    and

    //AJAX function to update page if hash changes
    function initializeFromUrl(fromLink) {
    
        /* code removed for readability */
    
    
        //take hash from function call or from the URL if not
        input = fromLink || window.location.hash ;
    
        //remove # from hash
        output = input.replace("#","");
    
    
    
        //get the URL of the AJAX content for new page
        pageId = output;
    
    
    
    
    
    
    var url = $(this).attr('href'),
    image = new Image();
    image.src = url;
    var clickedLink = $(this).attr('id');
    location.hash = clickedLink;
    image.onload = function () {
         $('#content').empty().append(image);
    };
    image.onerror = function () {
       $('#content').empty().html('That image is not available.');
    }
    $('#content').empty().html('Loading...');       
    
    
    
    
    }
    

    [EDIT :] Here is the full code for your page that should work, provided you can create a page that just outputs the image’s location from the database.

    var recentHash = "";
    var image_url ="";
    
    $(document).ready(function() {
    
        $('a.photo').click(function (event) {
            var clickedLink = $(this).attr('id');
            location.hash = clickedLink;
    
            event.preventDefault();
        });
    
    
        setInterval('pollHash()',100);
    
    });
    
    function pollHash() {
    
        //exit function if hash hasn't changed since last check
        if (window.location.hash==recentHash) {
            return; 
        }
        //hash has changed, update recentHash for future checks 
        recentHash = window.location.hash;
    
        //run AJAX to update page using page identfier from hash 
        initializeFromUrl(recentHash.substr(1));
    
    }
    
    
    //AJAX function to update page if hash changes
    function initializeFromUrl(fromLink) {
    
        /* code removed for readability */
    
    
        //take hash from function call or from the URL if not
        input = fromLink || window.location.hash ;
    
        //remove # from hash
        output = input.replace("#","");
    
    
    
        //get the URL of the AJAX content for new page
        pageId = output;
        if(pageId != ""){
            var temp_url = 'http://whitecu.be/user/mountain/'+pageId+'.html';
            $.get(temp_url, function(data) {
    
                image_url = data;
                image = new Image();
                image.src = image_url;
    
                image.onload = function () {
                    $('#content').empty().append(image);
                };
                image.onerror = function () {
                    $('#content').empty().html('That image is not available.');
                }
                $('#content').empty().html('Loading...');       
    
            });
    
    
    
        }else{
    
            window.location = "http://whitecu.be/user/mountain";
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Ben Almans plugin for hash change tracking: http://benalman.com/projects/jquery-hashchange-plugin/ Also I've modified my
I'm using http://benalman.com/projects/jquery-hashchange-plugin/ to listen for hash changes in my project, but his plugin
I'm using hashchange jQuery plugin from http://benalman.com/projects/jquery-hashchange-plugin/ to hook up an event when the
I'm using the jQuery plugin hashchange: http://benalman.com/projects/jquery-hashchange-plugin/ $(function(){ $(window).hashchange( function(){ // location.hash }) $(window).hashchange();
Using jQuery, how do I get the value from a textbox and then load
OK here goes, I'm using jQuery ajax to load post from inside a slider.
Using jQuery, how do you bind a click event to a table cell (below,
Using jQuery, what's the best way to find the next form element on the
Using jQuery, is there a way to select all tag that reference a specific
I have this jQuery ajax navigation tabs plugin that I created using some help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.