Allowing web editors to add javascript in EPiServer

March 13, 2007

I haven’t got much to do right now, except for some really small and easy EPiServer thingees. This is one of them:

The customer wanted to allow the web editors to add javascript in the Edit Mode that was then included in the <head> of the page. Easy to do.

1. Add the following code to the header.ascx file:
<%=GetJavaScript()%>

2. Then put the following method in the code-behind file:
protected string GetJavaScript()
{
if(CurrentPage.Property.Exists("Javascript"))
{
return CurrentPage.Property["Javascript"].ToString();
}
else
{
return String.Empty;
}
}

3. Add an XHTML property called “Javascript” to any pages where you wish to have javascript.

4. Write/paste the javascript in the text box for this property. However, make sure that you paste it in the HTML edit mode, not ordinary text mode. Otherwise EPiServer will just reformat your javascript to html, which isn’t pretty.

One Response to “Allowing web editors to add javascript in EPiServer”

  1. magnre Says:

    is there a way to fast att Google analytics code (i.e JavaScript) manually for a non episerver developer?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: