Note that there are some explanatory texts on larger screens.

plurals
  1. POload content via hashchange + jquery based on file name not in hash
    text
    copied!<p>I am using jquery + the hashchange plugin from ben alman. Below is a standard way to grab the hash name and load in content</p> <pre><code>$(window).hashchange(function() { var hash = location.hash; var array_url = hash.split('#'); var page = $(array_url).last()[0]; $('#content').load( page + '.php', function(){ }); }); </code></pre> <p>But is there any way to do this by grabbing some other variable assigned on a click function or sorted through php, perhaps?</p> <p>I am working with a multi-artist portfolio site that hands out unique three-four letter codes to images</p> <p>I'd like to serve these images up through unique urls. This has to be through ajax for many reasons.</p> <p>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. </p> <p>I am thinking this might just be impossible.</p> <p>Here is my current code </p> <pre><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(); </code></pre> <p>and my html / php : </p> <pre><code>$thethumb = customuniqueidfunc(); &lt;a href="[IMG URL]" class="photo gotdesc nohover" rel="&lt;?php echo $row['description'] ?&gt;" id="&lt;?php echo $thethumb; ?&gt;"&gt; </code></pre> <p>This works insofar as the image from the <code>href</code> attr loads into the <code>#content</code> div and the hash from the <code>id</code> 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. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload