Default HTML in Sharepoint 2007
As I’ve said before, I’ve been spending time with Sharepoint 2007 recently. The HTML it produces is really bad, and today I thought I show you just how bad.
Sharepoint 2007 has been “updated” to support masterpages, a concept from .NET 2.0. Sharepoint’s implementation of masterpages has several problems, but none of them even come close to the biggest problem of them all: default.master.
Default.master is the page that ships with Sharepoint and is used everywhere by default. A quick glimpse at it would make any seasoned web developer feel sick, and I quickly replaced it with something homemade. If you keep reading you will see why. Let’s get going with the first line:
Things start out really bad, without a doctype on the first line. This mean that all default pages will render in quirks mode, making rendering unreliable across browsers. Next they set an XML namespace, which after some googling points to very thorough documentation (pun intended). So they mean that it’s an XHTML document? No, because XHTML has lowercase tags, and here they use uppercase. The attribute
__expr-val-dir just doesn’t exist.
if (typeof(_spBodyOnLoadWrapper) != 'undefined')
The funniest thing here is the scroll attribute. Let me paraphrase htmlcodetutorial.com (found through quick googling):
SCROLL, which is only recognized by MSIE, indicates if there be scroll bars on the page. The default value is YES, so the only reason to use SCROLL is to set it to NO. SCROLL serves little purpose except to confuse and annoy readers by removing scroll bars which are there for a good reason.
_spBodyOnLoadFunctionNames.push("YourFunctionName");, and then that code will get run. Insane.
The next discovery can be found three nested tables later:
UpdateAccessibilityUI();return false;" href="#"
class="ms-skip">Turn on more accessible mode</a>
class="ms-skip" AccessKey="J">Skip to main content</a>
I’ll wait until you regain consciousness. Hi, welcome back. Yes, they are using
And this is where it starts to get ugly. Every Sharepoint page has a Personal menu and a Site menu on it, containing things you want to do with your account or the current site. Fair enough. This is the (rather lengthy) code for the Personal menu:
<menu type='ServerMenu' id="zz3_ID_PersonalActionMenu"
text="My Settings" description="Update your user information, regional settings, and alerts."
... [three more "ie:menuitem"] ...
<span title="Open Menu">
<div id="zz8_Menu_t" class="ms-SPLink ms-SpLinkButtonInActive"
onclick=" MMU_Open(byid('zz3_ID_PersonalActionMenu'), MMU_GetMenuFromClientId('zz8_Menu'),event,false, null, 0);"
oncontextmenu="this.click(); return false;" nowrap="nowrap">
... [five more eventhandlers] ...
Welcome Emil Stenström<img src="/_layouts/images/blank.gif" border="0" alt="Use SHIFT+ENTER to open the menu (new window)."/>
<img align="absbottom" src="/_layouts/images/menudark.gif" alt="" />
There’s several things worth a note here (in a bad way). The menu tag Sharepoint uses is in fact a real HTML tag, deprecated in HTML 4.01. Inside of that we have a tag called ie:menuitem that I really can’t understand. What on earth is ie:menuitem? Did they intentionally not make it work in other browsers? Everything is wrapped inside a
display: none; As you see, tags are also cluttered with event handlers, both real and made up ones. The contextmenu is blocked twice, and a spacer gif is used to add alternate text to the link. The menu icon is hardcoded into everything.
Default.master contains the worst code I’ve ever seen, and it’s really disappointing to see that from a product with “2007″ in it. Microsoft have failed in every possible way when it comes to the interface code, and I believe the only way out is to rebuild Sharepoint from scratch (not likely to happen). Having to work with Sharepoint is a real pain, and I honestly don’t recommend it to anyone. Put your curiosity to use into something more interesting, like the ASP.NET MVC Framework instead. Thanks for listening.