need to run code once rather than every time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay123
    New Member
    • Sep 2008
    • 121

    need to run code once rather than every time

    Hi,
    i am using window.onload in HTML code which is like
    Code:
    <script type="text/javascript" language="javascript">
        
        window.onload = function(){
          ShowPanel1(); 
          return false;
        }
        </script>
    where ShowPanel() is a function, now i have one dropdown in my form and their is a selectindexchan ged postback on it, so every time dropdown is changed , this above code runs. Is their any way that this code runs only once when page initially loads. something like postback check in javascript??

    Any help will be appreciated.

    Regards
    Jay
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I am not aware, that JavaScript can differenciate between initial load and reload, due to the stateless nature of HTTP.

    however you can use several tricks to tell the initial script, whether it should execute or not.
    - you can set a cookie, which you check before loading
    - you can make the server print or omit the JS code (e.g. depending on a session)
    - you can pass an URL parameter to suppress execution of the initial function
    - etc.

    Comment

    Working...