Apostrophe breaks JavaScript tag in Moveable Type content

Monday, 23. March 2009

Recently I ran into a problem with broken tag on content pages published using Moveable Type. The JavaScript tag simply breaks. Specifically, this happens when a blog entry title contains apostrophe. For example, the title of the blog entry is something like: Laura’s First Blog

In the Javascript tag, the code breaks where the variable is set. For example, if PageName variable were to set with the value: Laura’s Frist Blog, the apostrophe breaks the code as it essentially reads like it’s missing a closing quote.

Breaks:

PageName=’Lauras First Blog’ – apostrophe after Laura breaks the JavaScript tag

Fix:

PageName=’Laura\’s First Blog’ – to use apostrophe or other characters as a literal, escape them with a backslash

Leave a Reply