Using 'window.onload' in SharePoint pages#

My colleague Wouter just came up with a solution for some issues we were dealing with here at Tam Tam.

Using window.onload = function() ... in javascript breaks SharePoint's own system of getting functions run when the page is loaded. Two problems that I've seen as a result:

  • menus not folding out
  • Explorer view not working

This is how the SharePoint "on load" system works:

the body tag has this onload attribute:

onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();",

meaning: if "_spBodyOnLoadWrapper" exists, run it.

"_spBodyOnLoadWrapper" will execute all functions in the array "_spBodyOnLoadFunctionNames"
this array gets filled like this: _spBodyOnLoadFunctionNames.push("ExpGroupOnPageLoad");

When you use window.onload = function() ... for instance in core.js, it will replace the onload of the body, so "_spBodyOnLoadWrapper" will not be run. This means all the functions SharePoint wants to run on load are not run, which can cause various problems.

Solution:

Instead of using something like this:

window.onload = function() {

      randomizePicture();

      delayMenu();

}

use this:

_spBodyOnLoadFunctionNames.push('randomizePicture');

_spBodyOnLoadFunctionNames.push('delayMenu');

Wednesday, May 28, 2008 7:55:33 AM UTC #     | 

 

All content © 2012, Mart Muller
On this page
This site
Calendar
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts