coldkill Posted July 8, 2008 Share Posted July 8, 2008 Hey folks, at the moment I've created a script that hides/shows a navigation bar and side bar on my site. I'm now looking for a way of keeping these hidden when the user hides them after the page has been refreshed. Any ideas? I did try a search but didn't really know what to search for ¬¬ Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 Are you using a server side scripting language or just Javascript? Quote Link to comment Share on other sites More sharing options...
coldkill Posted July 8, 2008 Author Share Posted July 8, 2008 I'm going to be using PHP and MySQL on the site creating a Content Management System. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 I think the best way would be to use a session variable in php to determine whether or not to start the bar open or closed. It could be as simple as the php setting a variable for your javascript: <script language="Javascript"> var navbar = <?php echo $_SESSION['navbar'] ?>; </script> Quote Link to comment Share on other sites More sharing options...
coldkill Posted July 8, 2008 Author Share Posted July 8, 2008 But then how would I modify the session? Here's the code I've got at the moment which does two things: First it adjusts the display property of the specified element, secondly, it adjusts the width of the central content area. If I used your above sample, would I not need to reload the page and use php to adjust the session? Thanks for the help, Mike ::EDIT:: Helps if I attach the code ¬¬ This is in a separate .js file. // Content area width var contentWidth = 660; // Toggle the navigation bar function toggleDisplay( id ) { var element = document.getElementById( id ); var content = document.getElementById( "content" ); if( element.style.display == "none" ) { element.style.display = ""; // Adjust the content area variable contentWidth = contentWidth - 120; // Adjust content area width content.style.width = contentWidth; } else { element.style.display = "none"; // Adjust the content area variable contentWidth = contentWidth + 120; // Adjust content area width content.style.width = contentWidth; } } Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 You could have a hidden iframe object that loads a page that toggles the session variable. 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.