November Happy Hour will be moved to Thursday December 5th.

Programatically Adding OnLoad and OnUnLoad to Master Template

Vote:
 

I have a control to be added to one page of a site that requires the body tag to have onload and onunload events adding. I would prefer not to have a second copy of the master template just to allow these attributes to be added to the body tag, and all of the examples I have found for referencing the master page's body require runat="server" and an ID to be added to the master template, doing this stops the page displaying in EPiServer.

Is there a way of conditionally adding onload and onunload to the body tag, so it would look like the example below?

<body onload="load()" onunload="unload()">

#34554
Nov 09, 2009 14:13
Vote:
 

If you use jquery you can do like

$('body').ready(function() {
// do something funny
});

If not you can try to just use

window.onload = function() {
// Do something
}

#34555
Nov 09, 2009 14:35
Vote:
 

The jquery option is a good solution, thanks. With the following for the unload event.

$(window).unload(function() { unload(); });

 

#34565
Nov 09, 2009 16:42
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.