0

I have a visualforce page which is editable via the inline edit functionality provided by salesforce, or by clicking edit and being taken to a standard-ish edit page. I also have a popup that gets disabled (setting display attribute to none) once the page fully loads using javascript. I found that window.onload function seems to happen after the document.ready() function, so I'd like to disable the popup from the onload function. However, putting anything (an alert, for example) inside the window.onload function disables the inline edit functionality -- you can't dbl click anything and edit it (it works fine when the statement is placed in document.ready()). Any ideas why this is happening, and what I could do about it?

1 Answer 1

2

I presume that you tried something like this:

window.onload=function() {
  // do stuff here
}

This causes the body's onload function to be overwritten. You should not be using the classic event handler system for this reason; each event can only be handled once, and as it so happens, Visualforce hooks window.onload to do its thing regarding inline editing and more:

<body onUnload="if(this.bodyOnUnload)bodyOnUnload();"
      onBeforeUnload="if(this.bodyOnBeforeUnload){var s=bodyOnBeforeUnload();if(s)return s;}" 
      onLoad="if(this.bodyOnLoad)bodyOnLoad();" 
      class="hasMotif homeTab  net-withGlobalHeader sfdcBody brandQuaternaryBgr" 
      onFocus="if(this.bodyOnFocus)bodyOnFocus();">

Instead, use window.addEventListener in order to not interfere with Visualforce's library:

window.addEventListener('load', function() {
  // do stuff here
});

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .