Tuesday, September 27, 2011

window.onload being used in multiple places within the same application included

Recently one of my team members ran into an issue where we had used
the window.onload to dynamically set some values in a cookie object.
Our application handles multiple javascript files and we had used
window.onload in another jsp also for another reason.

So,when multiple jsp files are trying to add different functions to the window.onload event, only the last function was executing. We developed a workaround by adding the function that chains the onload event functions. Below snippet gives an example of how we solved it.

-
function addLoadEvent(functionName) {
var firstonload = window.onload;

if (typeof window.onload != 'function') {
window.onload =
functionName;
}
else {
window.onload = function() {
if (
firstonload ) {
firstonload();
}
functionName();
}
}
}


and the actual function definition is in the original jsp and this
function is called from there. So the first time window.onload may
not be a function so we are setting it, On subsequent assignments,
window.onload exists, so whatever it holds will be wrapped up with the
new function. the list grows like that...

6 comments:

Tom said...

It is very nice BTW! But If you really want to write something good, you can ask this guys for help! They really know how to write essay and will help you with homework! Just write to them thesis help and be happy about it! Enjoy!

Ariel Wilson said...

I almost facing a similar issue yesterday when I'm working on my dissertation posters projects, I try a lot of things and nothing worked for me, but finally, I got a perfect solution.

Goldyy said...

You can never go wrong when you order assignments from our reliable service. Our experts work fast and deliver top-notch content essayswriting org reviews. Don’t hesitate! Order papers at professional custom essay writing service and enhance your college performance.

bojo2112jon said...

Good day! That is not the same info what I am looking for, but at least something. After 3 years of working online there is not much information about any interesting top and new future powerful computer technologies. I was on the edge of trying luck with one online company checked reviews. And now I'm working at writing agency, that I could not even imagine. So, friends, click on this https://www.nursingpaper.com/our-services/nursing-essay-writing-service/ website and order your assignments online!

Whome1996 said...

I love to walk and therefore I prefer to spend time to my taste, and most students like this site https://essaysrescue.com/slader-review/, which helps in writing papers for every taste and color, experts will write the best paper, you will be delighted

Tommy543 said...

You can hire a qualified human editor to perfect your work. A do my essay seasoned professional who can polish your paper, get rid of mistakes, fix logical inconsistencies, and improve the overall quality of the text. The final result is a sure A+.