Allowing web editors to add javascript in EPiServer

by: Peter Hultgren (Sogeti)

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. This is the easiest way I could figure out:

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.

02 December 2007


Comments

  1. You could disable all buttons for the XHTMLLongString property, as you typically don't want any formatting or html markup at all in the javascript property.
Post a comment    
User verification Image for user verification  

About me

I am a 27 years old consultant at Sogeti in Stockholm, Sweden. I am working mainly with developing solutions in EPiServer, which I've been doing since 2006. I also write at Microserf and you can e-mail me at this address: peter.microserf@gmail.com.

Syndications


Archive


Tag cloud

EPiTrace logger