<?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>systemBash &#187; JavaScript</title>
	<atom:link href="http://systembash.com/tags/code-samples/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://systembash.com</link>
	<description>Technology and System Administration</description>
	<lastBuildDate>Sat, 12 May 2012 13:13:12 +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>Using Google Analytics Or Other Javascript With Smarty Template Engine</title>
		<link>http://systembash.com/content/using-google-analytics-or-other-javascript-with-smarty-template-engine/</link>
		<comments>http://systembash.com/content/using-google-analytics-or-other-javascript-with-smarty-template-engine/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 20:45:53 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=752</guid>
		<description><![CDATA[On a website I was working on recently I added the Google Analytics tracking code to the footer of a Smarty template, like this: footer.tpl: 1234567891011121314151617&#60;script type=&#34;text/javascript&#34;&#62; &#160; var _gaq = _gaq &#124;&#124; []; &#160; _gaq.push(['_setAccount', 'UA-XXXXX-XX']); &#160; _gaq.push(['_trackPageview']); &#160; (function() { &#160; &#160; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>On a website I was working on recently I added the <a href="www.google.com/analytics/">Google Analytics</a> tracking code to the footer of a <a href="http://www.smarty.net/">Smarty template</a>, like this:</p>
<p>footer.tpl:</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
<br />
&nbsp; var _gaq = _gaq || [];<br />
&nbsp; _gaq.push(['_setAccount', 'UA-XXXXX-XX']);<br />
&nbsp; _gaq.push(['_trackPageview']);<br />
<br />
&nbsp; (function() {<br />
&nbsp; &nbsp; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;<br />
&nbsp; &nbsp; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';<br />
&nbsp; &nbsp; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);<br />
&nbsp; })();<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></td></tr></tbody></table></div>
<p>However, since the javascript used by Google Analytics includes { and } tags, also used by the Smarty template engine, it tries to interpret this code and depending on your settings will either fail silently or or with an error such as this:</p>
<pre>Smarty error: [in footer.tpl line 148]: syntax error: unrecognized tag 'var'</pre>
<p>The fix is simple. Enclose your Google Analytics code, or other javascript code, with {literal} and {/literal}. The <a href="http://www.smarty.net/manual/en/language.function.literal.php">literal tag</a> allows you to place code to be displayed, well, literally.</p>
<p>The final code will look something like this:</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{literal}<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
<br />
&nbsp; var _gaq = _gaq || [];<br />
&nbsp; _gaq.push(['_setAccount', 'UA-XXXXX-XX']);<br />
&nbsp; _gaq.push(['_trackPageview']);<br />
<br />
&nbsp; (function() {<br />
&nbsp; &nbsp; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;<br />
&nbsp; &nbsp; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';<br />
&nbsp; &nbsp; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);<br />
&nbsp; })();<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<br />
{/literal}<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Your website should now run properly with the Google Analytics code in place.</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/using-google-analytics-or-other-javascript-with-smarty-template-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Secure Your Google Apps (Gmail, GDocs, GCal, etc)</title>
		<link>http://systembash.com/content/secure-gmail-google-apps-docs-gcal/</link>
		<comments>http://systembash.com/content/secure-gmail-google-apps-docs-gcal/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 11:12:41 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Configurations]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://systembash.com/content/secure-gmail-google-apps-docs-gcal/</guid>
		<description><![CDATA[If you are a Google user &#8211; meaning Gmail, Google Docs, Google Calendar, Google Reader, etc &#8211; then you should know that by default, once you log in your sessions are typically not encrypted between your browser and the Google servers. For some more technical information on this, check out dmiessler&#8217;s post on the subject. [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a Google user &#8211; meaning Gmail, Google Docs, Google Calendar, Google Reader, etc &#8211; then you should know that by default, once you log in your sessions are typically not encrypted between your browser and the Google servers. </p>
<p>For some more technical information on this, check out <a href="http://dmiessler.com/blogarchive/why-you-should-encrypt-all-of-your-google-activities-poc">dmiessler&#8217;s post on the subject</a>.</p>
<p>He mentions using bookmarks to make force your browser to use Google&#8217;s secure connections &#8211; however I&#8217;ve noticed that occasionally depending on how you arrive to your Google services that you will switch to an unencrypted session without warning.</p>
<p>For that reason, If you are using Firefox and <a href="https://addons.mozilla.org/en-US/firefox/addon/748">greasemonkey</a>, I highly recommend installing the &#8220;<a href="http://userscripts.org/scripts/show/5951">Google Secure Pro</a>&#8221; userscript. It automatically switches you from using http:// to https:// to ensure your data is encrypted to Google&#8217;s servers. This will increase your security greatly from using the unencrypted connections, which is good if you transfer confidential data over e-mail &#8211; like most normal people do!</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/secure-gmail-google-apps-docs-gcal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Closing a Firefox Window with Javascript</title>
		<link>http://systembash.com/content/close-firefox-window/</link>
		<comments>http://systembash.com/content/close-firefox-window/#comments</comments>
		<pubDate>Thu, 14 Sep 2006 20:26:19 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://systembash.com/content/close-firefox-window/</guid>
		<description><![CDATA[I recently had a problem where I was opening a browser window from an e-mail client. After taking a survey, I wanted a button to close this same window. In IE, it was fine to simply use window.close(); to close the window. However, Firefox, the evil genius that it is, will not let you do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a problem where I was opening a browser window from an e-mail client. After taking a survey, I wanted a button to close this same window. In IE, it was fine to simply use window.close(); to close the window. However, Firefox, the evil genius that it is, will not let you do that because it believes you did not click to open this window in the first place. In order to trick it, you quick load a blank page then close it. The code:</p>
<pre>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;a href=&quot;javascript:window.open('','_parent','');window.close();&quot;&gt;<br />
Close this window&lt;/a&gt;</div></td></tr></tbody></table></div>
</pre>
<p>So now, when you click the link, it closes the browser window. It works in both IE and Firefox 1.5 (and I believe others as well, but not personally tested).  Finding that snippet of code saved me a lot of time! So I hope someone else finds it useful.</p>
<p><em>Update, May 1 2008:</em></p>
<p>This code only works on Firefox 1.5 and IE. In Firefox 2.0, Unless a website opened up a window &#8211; it can not close it. So, in my case I want to close the window after a user takes a survey, opened from an email window. Firefox 2.0 gives this error:  <em>Scripts may not close windows that were not opened by the script</em>. I&#8217;m not sure what the right answer is here. They are doing it to prevent malicious scripts from closing windows. But even if they added an option to change that, most users wouldnt have it enabled by default.</p>
<p>So&#8230; where does that leave us? Please let me know if anyone knows of code that can close a window with Javascript in Firefox 2.x or 3.x.</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/close-firefox-window/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Greasemonkey + Duggmirror Script = Awesome</title>
		<link>http://systembash.com/content/digg-duggmirror-greasemonkey/</link>
		<comments>http://systembash.com/content/digg-duggmirror-greasemonkey/#comments</comments>
		<pubDate>Thu, 14 Sep 2006 00:07:56 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[NYU]]></category>

		<guid isPermaLink="false">http://systembash.com/content/digg-duggmirror-greasemonkey/</guid>
		<description><![CDATA[Don&#8217;t you hate it when you try to visit a digg story and the site has been dugg? Use the greasemonkey firefox plugin and this duggmirror greasemoney script to add three links to each digg entry &#8211; the duggmirror archive, Coral NYU Mirror, and the Google Cache of the page, all with a nice graphical [...]]]></description>
			<content:encoded><![CDATA[<div class="imageboxright"><img src="http://systembash.com/wp-content/uploads/2006/09/duggmirror.jpg" alt="Greasmoney + Duggmirror" /></div>
<p>Don&#8217;t you hate it when you try to visit a digg story and the site has been dugg? Use the greasemonkey firefox plugin and this duggmirror greasemoney script to add three links to each digg entry &#8211; the duggmirror archive, Coral NYU Mirror, and the Google Cache of the page, all with a nice graphical interface. It&#8217;s easy too:</p>
<ol>
<li>Install <a href="http://www.mozilla.com/firefox/">Firefox</a> (you mean you haven&#8217;t already?)</li>
<li>Install <a href="http://greasemonkey.mozdev.org/">Greasemonkey plugin</a></li>
<li>Restart Firefox</li>
<li>Visit the <a href="http://userscripts.org/scripts/show/1807">duggmirror script</a>&#8216;s page and click &#8220;install this script&#8221;. A little box will pop up at the top of the browser screen, asking you for permission to install it.</li>
</ol>
<p>That&#8217;s it! When you visit digg &#8211; you will see the extra links next to the post title. It works in any OS that firefox support (I&#8217;ve personally tested on Windows XP, Vista, and Ubuntu).</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/digg-duggmirror-greasemonkey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 17/22 queries in 0.005 seconds using disk: basic

Served from: systembash.com @ 2012-05-23 23:16:34 -->
