Tag Archives: Encode

joomla 1.5, ampersands and W3C validator

If you use joomla 1.5 and try to validate your DTD against W3C it is likely to have some errors related to ampersands.

This is due to a ¿bug? in default’s Joomla WYSIWYG editor (TinyMCE 2.0). By default this editor does not code the ampersands (&) to (&). If you try to write HTML using this editor and include a “&” you will notice it automatically changes “&” to “&”.

Getting rid of these annoying errors is quite simple. Just intall JCE (Joomla! Content Editor) plugin.

After the instalation is complete:

1. Log in to your administrator panel.
2. Click Site->Global Configuration.
3. Under the first tab (“Site”), find the parameter labelled “Default WYSIWYG Editor:”.
4. Select your JCE Editor 154 from the drop-down list (most likely the default editor was Tiny MCE 2.0.
5. Click the “Save” button in the toolbar.

Now validate your website again. You will get rid of those errors ;)

W3C validator issues with ampersand (&) in javascript location.href

When I tried to validate the code for http://www.hyips.es (one of my freelance projects) the validator kept complaining:

cannot generate system identifier for general entity langpair.

This error is caused by the validator parsing the code inside of a <script> tag. Below are the lines which were producing the error (related to a function which translates the page from spanish to english using google translator):

<script type="text/javascript"> 
function es2eng(){
  location.href = "http://translate.google.com/translate?u=" + this.location.href + "&langpair=es|en&h1=es&ie=UTF-8"; 
}
</script>
<a href="#" onclick="es2eng();"><img style="border: medium none; margin:1px;" src="/images/banderas/england-flag.gif" alt="translate to english" height="20" width="30" /></a>

After reading a lot of confussing comments (like Try to change ‘&’ to ‘&amp;’ or to ‘%26′), and just when I was about to define the function in an external js file (not a big fan of this, because the function was only one line long…), I came to this revealing post in webmasterworld.com.

The problem can be solved as easy as this: change

<script type="text/javascript">
your script is here
</script>

To:

<script type="text/javascript">
// <![CDATA[
your script is here
// ]]>
</script>

The change stops W3C’s validator from parsing the code inside the script tags, therefore the error disappears! :-)