How to detect the page is not just being refreshed ?

Posted on 2004-11-05
Last Modified: 2010-04-09
I have a table of links that is being used for a menu. The menu expands if you click on a menuitem (link) that has subitems and collapses if you click on it again. Pretty standard menu action but here is the problem. The menuitem selected is passed in the URL and if you hit refresh then it appears as if you  have clicked on the menu item. Thus it will toggle between expand/collapse.

What would be the best way to detect that someone has really clicked on the menu item link and not just hit refresh ?

If I pass something in the URL - it will be there as well on a refresh

If I use a form then the user gets the annoying "DO YOU WANT TO REPOST" alerts.

Question by:Bl248
    LVL 5

    Accepted Solution

    Use javascript to do the expand/collapse action for the menu.  I use the following code all the time for my menu's:

    function ToggleView(item) {
          var myItem = document.getElementById(item);
          if( == "none") {
       = "block";
          } else {
       = "none"

    That way you can have a link that when they click it, it opens/closes the menu.

    <a onclick="ToggleView('menuID');">Menu Item</a>

    <div id="menuID" style="display:none;">Menu stuff here</a>

    When you click on 'Menu Item', it will display open/close the div that has 'Menu stuff here'.  You can also do this with tables/spans/etc.
    LVL 5

    Expert Comment

    Also, this does not refresh the page, it merely modifies the items currently on it.  If they refresh the page, it will reset all the menu's to their default view (in my example this would be the hidden state).

    Author Comment

    Thanks - this looks interesting and I just remembered a client reqirement for this component and why I went down this road. The client wanted a Menu that would work without JS and was server based. I've been chasing a logic error for a day and completely forgot to mention this.

    This is why I ended up passing the menuitem details in the URL.

    Hum ... so if the current selected item = clicked item then collapse but not if this is a refresh.
    But without JS - not sure if this is doable.

    LVL 13

    Expert Comment


    "This uses just CSS 2 to turn nested lists into a working menu and does NOT use any JavaScript."
    LVL 13

    Assisted Solution

    This one is basically the same, but seems a bit more elegant.
    LVL 5

    Expert Comment

    Be wary though, the above methods are extremely buggy in Internet Explorer.
    LVL 75

    Expert Comment

    by:Michel Plungjan
    1. use a cookie to keep state of the click
    2. if cookies are turn off, let the user LIVE with the toggle
    3. use GET in the form to stop the "repost form"question

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now