Pages

Thursday, February 16, 2012

SharePoint and JavaScript

Today I wanted to edit a Wiki-Page in our company.

Well editing did work finy, up to the point where I wanted to add a JavaScript to a link.

Specifialy a OnClick-event.

First of all SharePoint doesn't support this type of link at all.
The only thing Sharepoint does undestand is "create a link" with some kind of url behind it.

Which will result in a <a href="linkToSite">Text</a> in HTML.

So I went for editing the HTML by myself.
The part where the link is definde was found quickly and the HTML tags for OnClick have been inserted:

HTML code now: <a href="#" OnClick="someJavaScriptStuff">Text</a>

As soon as I closed the HTML-editor on the SharePoint WYSIWYG editor it told me "Some of your HTML might been edited.".
So I reopened the HTML-editor and looked my link up again.

It looked like I left it.

I was like, great, it works.

Next step: Save page.

Okay, hit the link and.... nothing works.

Next step: Reedit page, go into HTML mode and:

THE OnClick-event WAS MISSING!

What on earth was the developer thinking, who implementet such a rule?
Honestly, HTML-Validator passes without errors, and SharePoint deletes this stuff silently?