SharePoint and Chrome


A few months ago I posted an entry called SharePoint 2010 Scrolling detailing a method to get scrolling working on less supported browsers in SharePoint 2010. Along with some background on to why the method works.

So, I’ve had reason recently to revisit Chrome and SharePoint compatibility specifically as of late. In the process a different fix came out of it. One that is less heavy-handed. But more importantly I found out that the cause of the scrolling inconsistency on some browsers like iOS Safari and Chrome is NOT due to the causes that have been previously documented by other bloggers or myself. The cause is in fact a timing issue around execution of a specific bit of very important onload JavaScript.

The bit that doesn’t execute (and causes a systemic issue, one of the issues it causes is the scrolling weirdness), is:

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

What this line means is basically if the page has loaded the onloadwrapper function from init.js. This onloadwrapper does a bunch of things, such as loading the ECMAScript for support SP.JS, executes page JavaScript for any onload events, and any client interactivity. So basically when this doesn’t execute pretty much no client side code from SharePoint can or will work, or any script that you have that relies on any of it. Scrolling is just the tip of the ice berg. Now for the good news, it’s easy to fix (I have a case in with Microsoft to look at including the fix in a future cumulative update).

Lastly, before showing the work around. SharePoint is not the only site affected by this issue, if you have a site loading JavaScript dynamically or via lazy loading and within that JavaScript have defined an OnLoad function, you can also run in to this issue.

$(document).ready(function()
{
	Reinit();
});

function Reinit()
{
	//verify we have finished loading init.js
	if(typeof(_spBodyOnLoadWrapper) != 'undefined')
	{
		//verify we have not already initialized the onload wrapper
		if(_spBodyOnloadCalled == false)
		{
			//initialize onload functions
			_spBodyOnLoadWrapper();
		}
	}
	//wait for 10ms and try again if init.js has not been loaded
	else
	{
		InitTimer();
	}
}

function InitTimer()
{
	setTimeout(Reinit,10);
}

  1. No comments yet.
(will not be published)


%d bloggers like this: