L
Laser Lips
Hi all.
I've got a single window application where there are no page loads or
page changes. All the content is dragged down via ajax including new
JavaScript code required for what ever is needed for the current
screen.
Most screens are broken up into files on the server.
Each file normally has some JavaScript and some HTML.
The JavaScript is spliced out and brought to life using the eval
command. most screens have a 'setUp' function, which is called after
the content is dowloaded to the page to initialise variables etc. Some
pages do not have this setUp function but I found that (seems obviouse
now) is that the JavaScript functions I was bringing down overwrite
any functions with the same name, and any that are not over written
are still present in the browser.
So if a page that get's ajaxed down does not have the setUp function,
and I call setUp, the setUp function is still trying to work with the
previous screen, but in fact should not have been called.
I've tried many things to clear out old functions but all methods have
proved inconsistant.
I've tried seperating the JavaScript into their own files and then
adding adn removing them from the head, but once loaded, even after
removing them, the functions they contained are still present.
I've declared functions like this...
function window.test()
{
}
then to remove them is used a loop like this...
for(n in window)
{
typov="typeof(window."+n+")";
typov=eval(typov);
if(typov.toString()=="function")
{
eval("window."+n+"=null;");
}
}
This worked quite well but the pages themselves that were ajaxed down
appeared not to be able to see the functions.
So my question is how can I load some functions, do what I need to do
and then remove them afterwards.
Thanks
Graham
I've got a single window application where there are no page loads or
page changes. All the content is dragged down via ajax including new
JavaScript code required for what ever is needed for the current
screen.
Most screens are broken up into files on the server.
Each file normally has some JavaScript and some HTML.
The JavaScript is spliced out and brought to life using the eval
command. most screens have a 'setUp' function, which is called after
the content is dowloaded to the page to initialise variables etc. Some
pages do not have this setUp function but I found that (seems obviouse
now) is that the JavaScript functions I was bringing down overwrite
any functions with the same name, and any that are not over written
are still present in the browser.
So if a page that get's ajaxed down does not have the setUp function,
and I call setUp, the setUp function is still trying to work with the
previous screen, but in fact should not have been called.
I've tried many things to clear out old functions but all methods have
proved inconsistant.
I've tried seperating the JavaScript into their own files and then
adding adn removing them from the head, but once loaded, even after
removing them, the functions they contained are still present.
I've declared functions like this...
function window.test()
{
}
then to remove them is used a loop like this...
for(n in window)
{
typov="typeof(window."+n+")";
typov=eval(typov);
if(typov.toString()=="function")
{
eval("window."+n+"=null;");
}
}
This worked quite well but the pages themselves that were ajaxed down
appeared not to be able to see the functions.
So my question is how can I load some functions, do what I need to do
and then remove them afterwards.
Thanks
Graham