The current time is

Wednesday, May 28, 2008

Your window.onload may cause problems in Sharepoint !!

Looks very smart of Sharepoint designers to have the scripting functions run in a systematic organized way... Personally, I love organization... Makes things defined and in order, not just haphazardly..

Sharepoint works as follows...
onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();",


So if one would like to execute some function onload of a page... doing so:
window.onload = function()
would really cause him trouble since he'll overwrite the sharepoint function calls...

So the smart way of doing this is to use:

_spBodyOnLoadFunctionNames.push('myFunction_01');
_spBodyOnLoadFunctionNames.push('
mySecondFunction');

This is how sharepoint really works ;) :) So we're following their way and voilaaa...

Reference: http://blogs.tamtam.nl/mart/UsingWindowonloadInSharePointPages.aspx

1 comment:

  1. Thank you, thank you, thank you!!!!!!!!!!!!!!! converted to 2010 and could no longer open Infopath form with createNewDocumentWithRedirect because javascript used window.onload to call function. Replaced window.onload with _spBodyOnLoadFunctionNames.push and presto!!!!

    ReplyDelete