Get url window.location.hash in php

I am using jquery tabbed interface here http://www.imashdigital.com/#2 and would like to return the tab number in php.

Ideally I would like to run a javascript function (by timer) that continually updates the php global variable with the current tab.

Based on this php value, 1 to 4, I will load another sidebar.

Any help and some code examples would be grateful as I am a beginner.

Yours faithfully

Jonathan

0


a source to share


3 answers


The portion of the URI that appears after the hash is never sent to the server. There is no way PHP can access it. Use the querystring ( $_GET

) parameter instead . Or use client side scripts (javascript).



+2


a source


I would suggest that you don't start the timer, but instead add $ .post to the activation of the "tab tab" event. This will change any contribution in real time and won't cause unnecessary requests.



+1


a source


I have used tabbed panels in a couple of recent projects and the solution I used is this:

Html

<ul class="tabs">
  <li><a href="#en_en">English</a></li>
  <li><a href="#fr_fr">FranΓ§ais</a></li>
</ul>
<div class="panel" id="en_en"><!-- Content --></div>
<div class="panel" id="fr_fr"><!-- Content --></div>

      

JQuery

// the currently selected tab, or a default tab (don't forget to prepend the #)
var tab = location.hash || '#en_en';

// register a click handler on all the tabs
$('ul.tabs a').click(function(event){
    event.preventDefault(); // prevents the browser from scrolling to the anchor

    // hide all panels, then use the link href attribute to find 
    // the matching panel, and make it visible
    // you can, of course, use whatever animation you like
    $('div.panel').hide().filter(  $(this).attr('href')  ).show();

).filter('[href*='+tab+']').click();
// above: in case of refreshing/bookmarking: find the tab link that contains
// the current location.hash, and fire its click handler

      

This works well because the server-side code doesn't have to know which tab is selected, but it also supports updating or bookmarking a specific tab without requiring the user to select the tab again.

0


a source







All Articles