Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Cookie | Q403 [ previous next ]

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?'

©2018 Martin Webb