Tag Archives: onload

Embedded Explorer View Not Working

Symptoms

Explorer View fails to launch when it is selected from the ‘Views:’ drop down on the top right of the document library web part (this is opposed to launching Explorer View by clicking ‘Actions’ -> ‘Open with Windows Explorer’).

In IE7 this should display Windows Explorer on the page itself embedded in an iframe, when this problem occurs the iframe displays a blank page instead. IE8 and IE9 a separate Windows Explorer window should be opened but the problem means it fails to do so.

Resolution

Upon selecting Explorer View the page does a post back and the JavaScript function that launches it (called ‘navtoframe2′) is meant to be called by the body’s onload event.

How this actually works:

The body element is contained in the master page while the document library itself will be in one of many content pages, these content pages also could have any number of functions on them that need to be called by the same onload event. Microsoft’s way of accomplishing this is by adding their names to a global array called ‘_spBodyOnLoadFunctionNames’ while the page is loading.

The master page’s onload event actually calls ‘_spBodyOnLoadWrapper()’, contained within the ‘LAYOUTS\1033\INIT.JS’ file, this goes through ‘_spBodyOnLoadFunctionNames’ calling each function.

The client’s issue was that someone had deleted the onload attribute from the body tag of a de-ghosted master page, this was a fairly easy fix by having them re-add it.

onload=”javascript:if (typeof(_spBodyOnLoadWrapper) != ‘undefined’) _spBodyOnLoadWrapper();”

While we’re on the subject of the onload event a good tip is to stay away from the window.onload property when working with SharePoint as this will be overwritten by the body’s onload attribute. I imagine JQuery’s (rather excellent) .ready() function would cause problems too.


Follow

Get every new post delivered to your Inbox.