There are at least two causes of JavaScript issues: incorrect configuration of a Sitecore client machine and attempting to embed JavaScript in HTML fields. This document describes resolutions to both.
Sitecore supports a fully patched Internet Explorer 6 and makes the best possible effort to support the latest release of Firefox as well. Sitecore strongly recommends Internet Explorer for the best possible user experience.
1. Sitecore Client and JavaScript Issues
A Sitecore client machine which does not meet minimum requirements or has not been configured correctly may throw JavaScript errors. On the Sitecore Developer Network (http://sdn.sitecore.net) see Products > Sitecore V5 > Installation Guide > Requirements > Client Requirements (http://sdn.sitecore.net/Products/Sitecore%20V5/Sitecore%20CMS%205,-d-,3/Installation/requirements.html) for a description of minimal Sitecore client environment requirements.
Patch the operating system and browser:
- As an administrator on the local machine, launch Internet Explorer
- Select Tools > Windows Update
- Select and install any appropriate updates (especially Service Pack 2 on Windows XP machines)
- Reboot if required and test again
The CMS server must be added to the Trusted Sites list in Internet Explorer:
- Launch the browser
- Access the CMS server
- Select Tools > Internet Options
- On the Security tab select Trusted Sites:
- Select Sites
- Select Add or otherwise ensure the CMS server is included in the Web Sites list (the “Require server verification” checkbox may need to be deselected)
- Close all open browser windows and test again
Some circumstances can apparently cause browsers to corrupt cached CSS and JavaScript. To resolve such issues:
- Close all browser windows
- In the Windows Control Panel choose Internet Options
- On the General tab select Delete Files
- Select the “Delete all offline content” checkbox and select OK
- Select Settings
- Ensure Automatically is selected
- Test again
Some software firewalls can insert code into JavaScript resources as they are being retrieved by the browser.
- Disable any software firewalls (Windows default firewall excluded)
- Clear the browser cache as described above
- (Potentially reboot and) test again
If none of these solutions resolve the issues, send screen shots of the Windows and Internet Explorer version identifiers to the partner or Sitecore support:
-
From the Windows start menu choose Run
- Enter winver
- Press ALT-PRTSCRN
- Paste into a Word document
-
In Internet Explorer
- Choose Help > About Internet Explorer
- Press ALT-PRTSCRN
- Paste into a Word document
2. JavaScript in HTML Fields
Sitecore strongly discourages attempting to embed JavaScript in fields of type HTML.
To provide user control of item-level JavaScript, add a field of type Memo to the appropriate template(s) to separate the markup from the code. For this example, imagine that the field is called Script.
In the appropriate rendering, check whether the Script field is populated and if so, output the opening <script> <!-- tag, the content of the Script field and the closing --></script> tag.
If it is absolutely necessary to embed the JavaScript in the content of the HTML field, a token can be inserted into the HTML field and the rendering can replace this token with the script tags enclosing the content of the memo field. Field security can be applied in the template to allow developers to maintain the JavaScript field while non-technical users can only maintain the HTML.