<?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>WEB2.0 trükkök&#124;&#124;WEB2.0 tricks &#187; XHTML</title>
	<atom:link href="http://web2.bitbaro.hu/en/tag/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://web2.bitbaro.hu</link>
	<description>HTML, CSS, JavaScript, PHP, Flex, Aptana, Jaxer, Python, Joomla, Administration, Linux</description>
	<lastBuildDate>Sun, 31 Jan 2010 23:14:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Detect if JavaScript is enabled, jump if no JS + W3C validator</title>
		<link>http://web2.bitbaro.hu/en/2009/03/10/javascript-detect/</link>
		<comments>http://web2.bitbaro.hu/en/2009/03/10/javascript-detect/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 09:57:55 +0000</pubDate>
		<dc:creator>Wedge</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://web2.bitbaro.hu/?p=13</guid>
		<description><![CDATA[Hogyan detektáljuk, hogy a JavaScript engedélyezve van-e a látogató böngészőjében úgy, hogy csak akkor irányítsuk át a felhasználót, ha nincs engedélyezve. Továbbá legyen böngészőfüggetlen a megoldás és a W3C validátor is tekintse szabványosnak.]]></description>
			<content:encoded><![CDATA[<p>A lot of people &#8211; fear of viruses, browser bugs, adverts &#8230; &#8211; simply turn off the JavaScript function of web browsers.  <span onmouseover="_tipon(this)" onmouseout="_tipoff()">This is a very great problem for today&#8217;s dynamic web pages or web applications</span>, <span onmouseover="_tipon(this)" onmouseout="_tipoff()">because in this case they could become completely ineffective.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()">The user doesn&#8217;t think of he/she turned off  JavaScript, but rather blame the producer of the page.</span><span onmouseover="_tipon(this)" onmouseout="_tipoff()"> This method gives a solution for this.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()">Redirect the user to a static page where we can explain why it is wrong to turn off the JavaScript</span> <img class="wp-smiley" src="../wp-includes/images/smilies/icon_smile.gif" alt=":-)" /></p>
<h3><span onmouseover="_tipon(this)" onmouseout="_tipoff()">What we want to achieve</span></h3>
<ul>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">We want to ensure, when JavaScript is turned off, </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()">redirect the browser </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()">to a static page or to an error page.</span></li>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">We would like to keep the XHTML compatibility</span></li>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">Work in all popular browser (Mozilla Firefox, Internet Explorer, 6-7-8, Opera, Safari, Google Chrome)</span></li>
</ul>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">I&#8217;ve never seen a solution posted anywhere like this, it&#8217;s my own idea. It&#8217;s a dirty hack</span><span onmouseover="_tipon(this)" onmouseout="_tipoff()">, but it works</span> <img class="wp-smiley" src="../wp-includes/images/smilies/icon_smile.gif" alt=":-)" /></p>
<p><span id="more-13"></span></p>
<h3>The way to the solition</h3>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">In order to be able to jump without JS, the following <em>meta</em> tag can be used:</span></p>
<pre class="xhtml" name="code">&lt;meta http-equiv="refresh" content="0; url=nojs.html" /&gt;</pre>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">If we place the above line to the header of the page, the browser immediately jump to the <em>nojs.html.</em></span></p>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">It would be an obvious solution if you have JavaScript, you can erase the above line  from the DOM and you are done.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()">But unfortunately, it won&#8217;t work, because the browser loads and compiles meta tags before the JavaScript can remove it&#8230;</span></p>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">Another obvious solution is to enclose the above line with &lt;noscript&gt; &lt;/ noscript&gt; tags</span><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">.</span> The problem with this solution is not standard compliant, maybe even not works in all browser</span><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">.</span> But it was in our terms that we must care of the XHTML standard.</span></p>
<h3><span onmouseover="_tipon(this)" onmouseout="_tipoff()">The solution</span></h3>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">First, here is the code and then explain in detail:</span></p>
<pre class="xhtml" name="code">&lt;!-- *** Javascript Detect Hack *** --&gt;
&lt;script type="text/javascript"&gt;&lt;!--
document.write("&lt;\/script&gt;&lt;script&gt;/*");
//--&gt;&lt;/script&gt;
&lt;meta http-equiv="refresh" content="0; url=nojs.html" /&gt;
&lt;script type="text/javascript"&gt;/* */&lt;/script&gt;
&lt;!-- ********* End of hack ******** --&gt;</pre>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">How does it work? </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()">If there is JavaScript, the script block before <em>&lt;meta&gt;</em> tag place the meta tag to a comment block, which won&#8217;t run this way.</span></p>
<p><strong>Line by line </strong>(without the first and the last line of comment):</p>
<ol>
<li>The start of the script block. <span onmouseover="_tipon(this)" onmouseout="_tipoff()">If there is JavaScript, it will run. </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()">The<br />
&#8220;&lt;!-&#8221; HTML comment at the beginning has to be there, because the script<br />
contains &#8220;&lt;&#8221;, &#8220;&gt;&#8221; signs, which can&#8217;t be in valid XHTML, and when the browser doesn&#8217;t know about &lt;script&gt;(or it is turned off) then it will miss this section.</span></li>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">We close the &lt;script&gt; block then open a new one with a start of a Javascript block comment.  This will hide the meta tag if the JavaScript is enabled.<br />
</span></li>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">This closes the first JavaScript block. When there is JavaScript this will be in comment, so won&#8217;t close anything. This must be in here because of the validator.</span></li>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">This will redirect the browser if there is no JS.</span></li>
<li><span onmouseover="_tipon(this)" onmouseout="_tipoff()">This line starts a new JS block. This is also in the JS comment, when JS is enabled until the &#8220;*/&#8221; characters. The &#8220;/*&#8221; is for the validator. And the last is the &lt;/script&gt;, which close the dynamically opened script tag or if the JavaScript is disabled it closes the &lt;sctipt&gt; started the start of the line.</span></li>
</ol>
<p><span onmouseover="_tipon(this)" onmouseout="_tipoff()">The point is that there are two levels and both level is correct without the other</span><span onmouseover="_tipon(this)" onmouseout="_tipoff()">. The first level is when JavaScript is enabled, and the code is dynamically changed, the<br />
other level is when there is no JS and the code is XHTML compliant.</span></p>
<h3>A further problem</h3>
<p>The user can turn off the meta refresh, although it is very uncommon.</p>
<h3>Example</h3>
<p>This is a working example: <a href="http://web2.bitbaro.hu/jshack/" target="_blank">http://web2.bitbaro.hu/jshack/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://web2.bitbaro.hu/en/2009/03/10/javascript-detect/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
