<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LogikDevelopment &#187; JavaScript</title>
	<atom:link href="http://www.logikdev.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logikdev.com</link>
	<description>&#34;Il n&#039;y a pas de problème, il n&#039;y a que des solutions. L&#039;esprit de l&#039;homme invente ensuite le problème.&#34; André Gide</description>
	<lastBuildDate>Tue, 20 Dec 2011 12:25:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Prevent double-click on HTML form</title>
		<link>http://www.logikdev.com/2011/06/29/prevent-double-click-on-html-form/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prevent-double-click-on-html-form</link>
		<comments>http://www.logikdev.com/2011/06/29/prevent-double-click-on-html-form/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 21:04:10 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[disable button]]></category>
		<category><![CDATA[double-click]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[onclick]]></category>
		<category><![CDATA[onsubmit]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1336</guid>
		<description><![CDATA[How many users are still double-clicking when they visit a website? It is not really a problem with links, but it could be with buttons. Let&#8217;s take, for example, a &#8216;contact us&#8217; form and a submit button which will send the content of the form by email to the website administrator. What happens if a [...]]]></description>
			<content:encoded><![CDATA[<p>How many users are still double-clicking when they visit a website? It is not really a problem with links, but it could be with buttons.<br />
Let&#8217;s take, for example, a &#8216;contact us&#8217; form and a submit button which will send the content of the form by email to the website administrator. What happens if a user double-click on the submit button? The form will be submitted twice and in consequence two emails will be sent instead of one.</p>
<p>There are multiple ways to fix this problem. The solution I will explain below is to disable the submit button once it has been pressed. In that way, even if the user double-clicks on it, the form will be submitted only once! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To disable the submit button once it has been pressed, you simply need to add the following JavaScript code in the <code>onclick</code> attribute of your button tag:</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
this.disabled=true;this.form.submit();
</pre>
<p>For example:</p>
<pre class="brush: xml; light: true; title: ; notranslate">
&lt;input name=&quot;submitButton&quot; id=&quot;submitButton&quot; type=&quot;submit&quot; value=&quot;Submit&quot; onclick=&quot;this.disabled=true;this.form.submit();&quot; /&gt;
</pre>
<p>The code above will work fine if you don&#8217;t have an <code>onsubmit</code> attribute in your form tag. But, if you have one, you will notice that the function <code>this.form.submit()</code> will not execute the content of the <code>onsubmit</code> attribute. In that case, you need to force the call as shown below:</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
this.disabled=true;if(this.form.onsubmit()){this.form.submit();}else{this.disabled=false;}
</pre>
<p>However, it is recommended to move whatever you have in the <code>onsubmit</code> attribute in the button onclick, such as:</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
this.disabled=true;if(validateForm()){this.form.submit();}else{this.disabled=false;}
</pre>
<p><br/><strong>NOTE:</strong><br />
If in your code, you are using the following to check if the form has been submitted:</p>
<pre class="brush: php; light: true; title: ; notranslate">
if (isset($_POST['submitButton'])) { echo &quot;Form submitted!&quot;; }
</pre>
<p>It will need to be replaced by the following:</p>
<pre class="brush: php; light: true; title: ; notranslate">
if ($_SERVER['REQUEST_METHOD'] == &quot;POST&quot;) { echo &quot;Form submitted!&quot;; }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/06/29/prevent-double-click-on-html-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect if JavaScript is enabled</title>
		<link>http://www.logikdev.com/2011/04/19/detect-javascript-enabled/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=detect-javascript-enabled</link>
		<comments>http://www.logikdev.com/2011/04/19/detect-javascript-enabled/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 21:05:49 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1230</guid>
		<description><![CDATA[Because of the emergence of Ajax, people don&#8217;t disable JavaScript much nowadays. I don&#8217;t know the percentage of people having disabled JavaScript. It is likely under 5%. But if you have a website visited by millions of visitors every month, even 1% is matter! This is why I wrote the following code: The text under [...]]]></description>
			<content:encoded><![CDATA[<p>Because of the emergence of Ajax, people don&#8217;t disable JavaScript much nowadays.<br />
I don&#8217;t know the percentage of people having disabled JavaScript. It is likely under 5%. But if you have a website visited by millions of visitors every month, even 1% is matter!</p>
<p>This is why I wrote the following code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;noscript&gt;JavaScript is DISABLED.&lt;/noscript&gt;
&lt;span id=&quot;displayIfJavaScript&quot; style=&quot;display:none&quot;&gt;JavaScript is ENABLED.&lt;/span&gt;

&lt;script&gt;
document.getElementById('displayIfJavaScript').style.display = &quot;block&quot;;
&lt;/script&gt;
</pre>
<p>The text under the <code>noscript</code> tag will be displayed if JavaScript is disabled or not supported. The text under the <code>span</code> tag is not displayed by default and will be showed using JavaScript, this is why we can be sure JavaScript is enabled in that case.<br />
You can obviously change the content of the <code>noscript</code> and <code>span</code> tags. You could, for example, hide a form which uses JavaScript validation to non-JavaScript users by putting the HTML code of the form under the <code>span</code> tag.</p>
<p>Please see below the above script in action:<br />
<strong><noscript>JavaScript is DISABLED.</noscript><span id="displayIfJavaScript" style="display:none">JavaScript is ENABLED.</span></strong><script>document.getElementById('displayIfJavaScript').style.display = "block";</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/04/19/detect-javascript-enabled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Close ModalPanel if no error</title>
		<link>http://www.logikdev.com/2011/04/03/close-modalpanel-no-error/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=close-modalpanel-no-error</link>
		<comments>http://www.logikdev.com/2011/04/03/close-modalpanel-no-error/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 22:04:03 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[maximumSeverity]]></category>
		<category><![CDATA[ModalPanel]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=90</guid>
		<description><![CDATA[It has been a very long time I wrote this code, but I thought I would share it with you as it is quite useful. If like me, you are an adept of RichFaces, you might have already seen and used the modal panel functionality. By default, a modal panel is used to display a [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a very long time I wrote this code, but I thought I would share it with you as it is quite useful.</p>
<p>If like me, you are an adept of RichFaces, you might have already seen and used the modal panel functionality. By default, a modal panel is used to display a message, but what if you actually want to display a form within it? How nice would it be if, for example, you could put your login form in a modal panel instead of opening a new page?</p>
<p>With the following steps, you will be able to achieve this:</p>
<ul>
<li>First, get the maximum severity in the message queue:
<pre class="brush: xml; title: ; notranslate">
&lt;a4j:outputPanel ajaxRendered=&quot;true&quot;&gt;
    &lt;h:form style=&quot;display:none&quot; id=&quot;maximumSeverityForm&quot;&gt;
        &lt;h:inputHidden id=&quot;maximumSeverity&quot;
            value=&quot;#{facesContext.maximumSeverity.ordinal}&quot;/&gt;
    &lt;/h:form&gt;
&lt;/a4j:outputPanel&gt;
</pre>
<p>This form has to be placed on all your pages using an include for example. This form will basically get refreshed on every postback and will contain the maximum severity in the message queue or null if the queue is empty.
</li>
<li>Create a JavaScript method which reads the <code>maximumSeverity</code> hidden field:
<pre class="brush: jscript; title: ; notranslate">
function ajaxRequestContainsErrors() {
    return document.getElementById(&quot;maximumSeverityForm:maximumSeverity&quot;).value &gt; 0;
}
</pre>
<p>This method has to also be included in all the pages.
</li>
<li>Finally, use the following code for the &#8220;Submit&#8221; button in your form:
<pre class="brush: xml; title: ; notranslate">
&lt;a4j:commandButton action=&quot;#{userBean.loginAction}&quot; value=&quot;Submit&quot; oncomplete=&quot;if (!ajaxRequestContainsErrors()) {Richfaces.hideModalPanel('loginModalPanel');}&quot;/&gt;
</pre>
<p>This button is actually checking if there is no error before closing the modal panel.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/04/03/close-modalpanel-no-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate file size prior upload</title>
		<link>http://www.logikdev.com/2010/08/26/validate-file-size-prior-upload/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validate-file-size-prior-upload</link>
		<comments>http://www.logikdev.com/2010/08/26/validate-file-size-prior-upload/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 20:53:37 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[file input]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[fileSize function]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=687</guid>
		<description><![CDATA[If I ask you what is the most complex thing in HTML, what would you reply? For me, it would be the file upload (or maybe character encoding, but this is not the topic! ). One of the problem around the file upload functionality is that there is, no matter what, a file size limit [...]]]></description>
			<content:encoded><![CDATA[<p>If I ask you what is the most complex thing in HTML, what would you reply?<br />
For me, it would be the file upload (or maybe character encoding, but this is not the topic! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ).</p>
<p>One of the problem around the file upload functionality is that there is, no matter what, a file size limit set on the server. The limit could be 100Kb such as 100Mb depending on the configuration of the server.<br />
But what happens if the user tries to upload a file bigger than the limit?<br />
It&#8217;s simple, the file is going to be uploaded on the server until the limit is reached. Once it happens, the server returns an error message to the client.<br />
Well, this is not ideal!<br />
Indeed, depending on the connection speed of the user, the error message could be displayed a few minutes later. And you know how impatient users are! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So obviously, the solution would be to validate the file size before the upload starts.<br />
To do that, we can simply use the <code>fileSize</code> Javascript function against the upload field.<br />
But, surprising enough, this function doesn&#8217;t work on Internet Explorer! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' /> </p>
<p>And the only solution I found to get the file size with IE was using ActiveX:</p>
<pre class="brush: jscript; title: ; notranslate">
var oas = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
var e = oas.getFile(document.forms[0].file.value);
var size = e.size;
</pre>
<p>Finally, here is the whole Javascript function to validate the file size:</p>
<pre class="brush: jscript; title: ; notranslate">
function validateFileSize(file, maxSize) {
	if (navigator.appName==&quot;Microsoft Internet Explorer&quot;) {
		if (file.value) {
			var oas = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
			var e = oas.getFile(file.value);
			var size = e.size;
		}
	} else {
		if (file.files[0]!=undefined) {
			var size = file.files[0].fileSize;
		}
	}
	if (size!=undefined &amp;&amp; size &gt; maxSize)
		return false;
	return true;
}
</pre>
<p>with <code>file</code> the file input field to validate and <code>maxSize</code> the maximum size in bits.</p>
<p>For example, you can call this function as follow:</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
validateImageSize(document.forms[0].file, 500000)
</pre>
<p><br/>I successfully tested this code on:</p>
<ul>
<li>Google Chrome 6;</li>
<li>Firefox 3.6;</li>
<li>Internet Explorer 6;</li>
<li>Internet Explorer 7.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/08/26/validate-file-size-prior-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate your EAN barcode</title>
		<link>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validate-your-ean-barcode</link>
		<comments>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/#comments</comments>
		<pubDate>Thu, 13 May 2010 21:04:33 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[EAN barcode]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=520</guid>
		<description><![CDATA[On one of the applications I am working on, I had to validate an EAN (European Article Number) barcode. This application is mostly using JavaScript validation so I asked my friend Google to find me a JavaScript method which would check my EAN barcode. It found validators in different languages but none in JavaScript. Because [...]]]></description>
			<content:encoded><![CDATA[<p>On one of the applications I am working on, I had to validate an EAN (<a target="_blank" href="http://en.wikipedia.org/wiki/European_Article_Number">European Article Number</a>) barcode.<br />
This application is mostly using JavaScript validation so I asked my friend Google to find me a JavaScript method which would check my EAN barcode.<br />
It found validators in different languages but none in JavaScript. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Because one is never better served than by oneself, I decided to write it myself and share it with you. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="brush: jscript; title: ; notranslate">
function checkEan(eanCode) {
	// Check if only digits
	var ValidChars = &quot;0123456789&quot;;
	for (i = 0; i &lt; eanCode.length; i++) {
		digit = eanCode.charAt(i);
		if (ValidChars.indexOf(digit) == -1) {
			return false;
		}
	}

	// Add five 0 if the code has only 8 digits
	if (eanCode.length == 8 ) {
		eanCode = &quot;00000&quot; + eanCode;
	}
	// Check for 13 digits otherwise
	else if (eanCode.length != 13) {
		return false;
	}

	// Get the check number
	originalCheck = eanCode.substring(eanCode.length - 1);
	eanCode = eanCode.substring(0, eanCode.length - 1);

	// Add even numbers together
	even = Number(eanCode.charAt(1)) +
	       Number(eanCode.charAt(3)) +
	       Number(eanCode.charAt(5)) +
	       Number(eanCode.charAt(7)) +
	       Number(eanCode.charAt(9)) +
	       Number(eanCode.charAt(11));
	// Multiply this result by 3
	even *= 3;

	// Add odd numbers together
	odd = Number(eanCode.charAt(0)) +
	      Number(eanCode.charAt(2)) +
	      Number(eanCode.charAt(4)) +
	      Number(eanCode.charAt(6)) +
	      Number(eanCode.charAt(8)) +
	      Number(eanCode.charAt(10));

	// Add two totals together
	total = even + odd;

	// Calculate the checksum
    // Divide total by 10 and store the remainder
    checksum = total % 10;
    // If result is not 0 then take away 10
    if (checksum != 0) {
        checksum = 10 - checksum;
    }

	// Return the result
	if (checksum != originalCheck) {
		return false;
	}

    return true;
}
</pre>
<p>Note that this code can validate EAN-8 and EAN-13 barcodes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Onclick event is not fired on IE</title>
		<link>http://www.logikdev.com/2009/12/08/onclick-event-is-not-fired-on-ie/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=onclick-event-is-not-fired-on-ie</link>
		<comments>http://www.logikdev.com/2009/12/08/onclick-event-is-not-fired-on-ie/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 23:05:58 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[onclick]]></category>
		<category><![CDATA[Return key]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=175</guid>
		<description><![CDATA[I am pretty sure everybody knows that Internet Explorer has &#8220;a few&#8221; bugs&#8230; You didn&#8217;t? Alright, better to stay on your little cloud and leave this blog right away! For the others, I will talk about the JavaScript event onclick which is not fired when the following requirements are matched: In a form; There is [...]]]></description>
			<content:encoded><![CDATA[<p>I am pretty sure everybody knows that Internet Explorer has &#8220;a few&#8221; bugs&#8230;  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /><br />
You didn&#8217;t? <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /> Alright, better to stay on your little cloud and leave this blog right away!</p>
<p>For the others, I will talk about the JavaScript event <strong>onclick</strong> which is not fired when the following requirements are matched:</p>
<ul>
<li>In a form;</li>
<li>There is only ONE input text element;</li>
<li>There is one button which has an <code>onclick</code> event assigned;</li>
<li>You press the &#8216;Enter&#8217; button inside the input text element.</li>
</ul>
<p>For a better understanding, let&#8217;s now take the following example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
    &lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;head&gt;
    &lt;body&gt;
        &lt;form&gt;
            &lt;input type=&quot;text&quot; id=&quot;t1&quot;/&gt;
            &lt;input type=&quot;submit&quot; onclick=&quot;alert('onclick fired!'); return true;&quot;/&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>As you can see, there is nothing difficult in this code.<br />
Well, that doesn&#8217;t mean Internet Explorer can handle it&#8230;  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_lol.gif' alt=':lol:' class='wp-smiley' /> </p>
<p>The bug occurs if you press the &#8216;Enter&#8217; button inside the input text element using Internet Explorer. Indeed, the <code>onclick</code> event is not fired and the text &#8216;onclick fired!&#8217; is not display to the user! However, it works perfectly fine on Firefox and Safari.</p>
<p>The funny thing is this code works on Internet Explorer if you add another input text, even if it is hidden!<br />
Why? Don&#8217;t ask me! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_neutral.gif' alt=':-|' class='wp-smiley' /> </p>
<p>Anyway, the following example works on IE:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
    &lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;head&gt;
    &lt;body&gt;
        &lt;form&gt;
            &lt;input type=&quot;text&quot; id=&quot;t1&quot;/&gt;
            &lt;input type=&quot;text&quot; style=&quot;display:none&quot;/&gt;
            &lt;input type=&quot;submit&quot; onclick=&quot;alert('onclick fired!'); return true;&quot;/&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p><br/>Why are we assigning an <code>onclick</code> event to the submit button?<br />
It could be for a lot of reasons, but the main one is probably to validate the form before submitting the data.</p>
<p>By the way, RichFaces is very often using this event on the submit buttons.<br />
So remember to add a hidden input text to your form if you want to allow users to use the &#8216;Return&#8217; key. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2009/12/08/onclick-event-is-not-fired-on-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Be careful of SKIP_COMMENTS</title>
		<link>http://www.logikdev.com/2009/12/01/be-careful-of-skip_comments/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=be-careful-of-skip_comments</link>
		<comments>http://www.logikdev.com/2009/12/01/be-careful-of-skip_comments/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 20:25:33 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[old browsers]]></category>
		<category><![CDATA[SKIP_COMMENTS]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=147</guid>
		<description><![CDATA[In the early days, we used to hide JavaScript code from old browsers that do not support JavaScript. The way of doing this was to put a one-line HTML-style comment without the closing characters immediately after the opening &#60;script&#62; tag and put //--&#62; at the end of the script. For example: However if you are [...]]]></description>
			<content:encoded><![CDATA[<p>In the early days, we used to hide JavaScript code from old browsers that do not support JavaScript.<br />
The way of doing this was to put a one-line HTML-style comment without the closing characters immediately after the opening <code>&lt;script&gt;</code> tag and put <code>//--&gt;</code> at the end of the script.</p>
<p>For example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
alert('Test');
//--&gt;
&lt;/script&gt;
</pre>
<p>However if you are using this trick with the initialization parameter <code>facelets.SKIP_COMMENTS</code> set to <strong>true</strong>, the code between <code>&lt;!--</code> and <code>//--&gt;</code> won&#8217;t even be sent to the client!<br />
It simply means that the code above won&#8217;t open an alert window because it has been skipped during the page rendering.</p>
<p>Here is what the client will receive:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
//--&gt;
&lt;/script&gt;
</pre>
<p><br/>You have two solutions to avoid this situation:</p>
<ol>
<li>Set the <code>SKIP_COMMENTS</code> parameter to false (the default is true). This can&#8217;t really hurt, your page will just be heavier depending on how much HTML comments you put on your page;</li>
<li>No need to hide the JavaScript code as all browsers are now supporting it and over 99.9% of users have it enabled &#8211; this is the solution I chose.</li>
</ol>
<p>For information, below is the code to put in your web.xml file to set the <code>SKIP_COMMENTS</code> parameter to false:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;context-param&gt;
    &lt;param-name&gt;facelets.SKIP_COMMENTS&lt;/param-name&gt;
    &lt;param-value&gt;false&lt;/param-value&gt;
&lt;/context-param&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2009/12/01/be-careful-of-skip_comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

