Darghon Posted April 21, 2009 Share Posted April 21, 2009 Hello all I have a page that has multiple tab pages, the tabs can be opened by clicking on them, and it all works via javascript. I changed the tab clicking code to append the address bar with #tabname So a user can choose a tab and the address bar will change without the page refreshing. Now when a user presses refresh, I'd like to read the # value so I know what tab I need to put open. Is this possible with PHP, or does it have to be done with JavaScript, if so let me know and I'll move this topic to the JavaScript part. So I want to be able to get the following from the example link: http://Localhost/Website/Realm.php?c=Town&b=1#info c = Town b = 1 # = info so that I can select info as the opened tab Thx in advance Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 21, 2009 Share Posted April 21, 2009 You will need to use JavaScript as anchors are only processed Client Side: var url = window.location.href; var anchor = url.substr(url.indexOf('#')+1); alert(anchor); Quote Link to comment Share on other sites More sharing options...
Darghon Posted April 22, 2009 Author Share Posted April 22, 2009 I've been trying to get it to work, but this is how my setup is in the webpage I have 1 include that contains the entire websites javascript code. so in there I made a function like this => document.onload = function setTab(){ alert("trigger"); var url = window.location.href; var anch = url.substr(url.indexOf('#')+1); alert(anch); if(anch != ""){ toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), anch); alert(anch); } } the toggleTab function works, but it won't load this function on a onload event The javascript page is imported at the top of the page (and must stay there) Quote Link to comment Share on other sites More sharing options...
Darghon Posted April 22, 2009 Author Share Posted April 22, 2009 changed the function to window.onLoad = function setTab(){ var url = window.location.href; var anch = url.substr(url.indexOf('#')+1); if(anch != ""){ toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), anch); } } And it works great now. Thx Quote Link to comment Share on other sites More sharing options...
Darghon Posted April 22, 2009 Author Share Posted April 22, 2009 changed the function to window.onLoad = function setTab(){ var url = window.location.href; var anch = url.substr(url.indexOf('#')+1); if(anch != ""){ toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), anch); } } And it works great now. thanks First sorry for triple post, but can't edit my previous... the code won't work like that, the error with it is, if no # is found in the address line, then it'll use the complete address line instead of nothing. To fix this I changed the function to => window.onload = function(){ var url = window.location.href; if(url.indexOf('#') != -1){ toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), url.substr(url.indexOf('#')+1)); } } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 22, 2009 Share Posted April 22, 2009 good call...forgot about that case Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.