Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q403 How do you get a page to perform something only on the initial load, and not when reloaded? Is it done with cookies?

irt.org | Knowledge Base | JavaScript | Cookie | Q403 [ previous next ]

Q403 How do you get a page to perform something only on the initial load, and not when reloaded? Is it done with cookies?

It can be done using cookies, although a lot of people disable cookies. Another alternative is to have a frameset with a hidden frame. You store a variable in the parent frame which says whether the main frame has already been loaded. Each time the main frames loads it checks the parent frame for the variable value to see whether it should perform the once only code:

<head>
<script language="JavaScript"><!--
var displayed_it_yet = false;
//--></script>
</head>

<frameset rows="100%,*">
<frame src="mainpage.htm">
<frame src="about:blank">
</frameset>

And then in mainpage:

<script language="JavaScript"><!--
function check_first() {
    if (!parent.displayed_it_yet) {
        // code to perform
        parent.displayed_it_yet = true;
    }
}
//--></script>

Feedback on 'Q403 How do you get a page to perform something only on the initial load, and not when reloaded? Is it done with cookies?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.