View Full Version : Prototype only works after refresh

11-04-2011, 08:59 PM
I'm having an issue with prototype...
I have the following code that I want to execute:

Event.observe(window, 'load', function(){
$('cancelTour').observe('click', function(){

the very first time it's loaded, it doesn't work, but if the page is refreshed, it works perfectly. is there something I'm missing?

11-04-2011, 10:34 PM
Can you post a link to your page? (If not, posting all of the source code might help.)

I don't know what the problem is, but one guess is that this is an issue of delayed loading.

When you load a page for the first time, it might take a few extra seconds (or even just milliseconds) to load all of the external files such as Javascript. This means that if you are trying to interact with some code that might not have loaded yet, it probably won't work.

Once the page has already been loaded, then that content is cached and it loads instantly when you 'refresh' the page.

If you do a forced reload (for example, in Firefox, shift+ctrl+r), then does it still work? That would be a way to test this.

If that is the problem, then reordering the content in your source code might help, or you could make sure that everything is included in the same external file so that it all is guaranteed to load at the same time.

11-07-2011, 04:42 PM
ive tried a number of variations on order, placing the code directly in the page, placing it in a file and linking to the file... nothing works... but other javascript functions work correctly... just not the new ones i've added. this site was managaged by someone else previously and i recently am taking it over.
to test get it to duplicate the issue ive been resetting the browser each time, clearing out everything...
to log in, use tester@fakenstein.com, password 123456