<?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>Flogging English &#187; javascript</title>
	<atom:link href="http://floggingenglish.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://floggingenglish.com</link>
	<description>Too close for missiles; switching to guns....</description>
	<lastBuildDate>Fri, 04 May 2012 04:30:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Navigating the changing IE landscape</title>
		<link>http://floggingenglish.com/2010/10/18/navigating-the-changing-ie-landscape/</link>
		<comments>http://floggingenglish.com/2010/10/18/navigating-the-changing-ie-landscape/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 03:51:57 +0000</pubDate>
		<dc:creator>retsoced</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[compatibility mode]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[IE 7]]></category>
		<category><![CDATA[IE 9]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[meta tags]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[quirks]]></category>
		<category><![CDATA[Server 2003]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://floggingenglish.com/?p=1453</guid>
		<description><![CDATA[Now that the IE 9 beta is available, people have started popping up on some of the stats of a few of the websites I maintain, and this is proving to be just as troublesome as just about every other new release of IE. The thing I noticed right off the bat, in fact it [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Now that the <strong><a title="IE 9 testdrive" href="http://ie.microsoft.com/testdrive/" target="_blank">IE 9 beta</a></strong> is available, people have started popping up on some of the stats of a few of the websites I maintain, and this is proving to be just as troublesome as just about every other new release of IE. The thing I noticed right off the bat, in fact it was impossible to miss, is that a site running a DHTML menu throws JavaScript errors like they were free, but only in IE 9, and only if it is <strong><em>not</em></strong> in compatibility mode. So, rather than monkey about in some damn fugly JavaScript, I opted to just set the site to force IE to render in compatibility mode.</p>
<p>There are a couple of ways to do this, the most basic is to drop a meta tag in the head:</p>
<pre style="padding-left: 30px;">&lt;meta http-equiv="X-UA-Compatible" content="IE=7" /&gt;</pre>
<pre style="padding-left: 30px;">or</pre>
<pre style="padding-left: 30px;">&lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /&gt;</pre>
<p>This way would have been laborious and quite tedious going through all of the pages in the site and making sure the ones that are not content managed have this new tag. Meh &#8211; so not doing that.</p>
<p>The way I opted for was to simply add it as a custom header in IIS (thanks to <strong><a title="Joel Varty" href="http://weblogs.asp.net/joelvarty/archive/2009/03/23/force-ie7-compatibility-mode-in-ie8-with-iis-settings.aspx" target="_blank">Joel Varty</a></strong> for the nudge), and be done with it. It&#8217;s pretty simple, just open up the IIS snap-in, right click on your site and open properties. Select the  HTTP Headers tab, click add then enter &#8220;X-UA-Compatible&#8221; in the custom header name field, and &#8220;IE=7&#8243; or &#8220;IE=EmulateIE7&#8243; in the custom header value field. I used the IE=EmulateIE7 value because it seems to be the most flexible, and doesn&#8217;t absolutely force IE7 rendering, especially for pages using Quirks mode.</p>
<p>Pretty simple: now it&#8217;s all fine for even the most cutting edge of IE users.</p>
<p>You&#8217;re welcome.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffloggingenglish.com%2F2010%2F10%2F18%2Fnavigating-the-changing-ie-landscape%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div class="shr-publisher-1453"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://floggingenglish.com/2010/10/18/navigating-the-changing-ie-landscape/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Return from the 3rd level of malware hell</title>
		<link>http://floggingenglish.com/2010/08/08/return-from-the-3rd-level-of-malware-hell/</link>
		<comments>http://floggingenglish.com/2010/08/08/return-from-the-3rd-level-of-malware-hell/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 19:19:50 +0000</pubDate>
		<dc:creator>retsoced</dc:creator>
				<category><![CDATA[Blatherings]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Geeking Out]]></category>
		<category><![CDATA[adware]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[malicious code]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://floggingenglish.com/?p=1400</guid>
		<description><![CDATA[There are days, that the interwebs suck dynamically placed, interactive Donkey Balls. Yesterday, was one of those days. Come to find out at some point on Friday, Flogging English was, for lack of a better word, hacked. Two JavaScript files had some malicious code embedded in them that tried to do something well&#8230;. malicious. What? [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignright size-full wp-image-1401" title="confused" src="http://floggingenglish.com/media/contentMedia//2010/08/confused.jpg" alt="wait... what?" width="225" height="345" />There are days, that the interwebs suck dynamically placed, interactive Donkey Balls. Yesterday, was one of those days.</p>
<p>Come to find out at some point on Friday, Flogging English was, for lack of a better word, hacked. Two JavaScript files had some malicious code embedded in them that tried to do something well&#8230;. malicious. What? Dunno man, I just deleted that shit.</p>
<p>Google alerted me late in the day on Friday, meaning I didn&#8217;t see it until I checked my email a mere 30 minuted before my scheduled <strong><a title="Saturdays half century" href="http://maps.google.com/?q=http://share.abvio.com/40bf/d3cb/4c1b/ecbb/Cyclemeter-Cycle-20100807-1011.kml" target="_blank">50 mile ride</a></strong>. I fumbled about a bit, did several full searches of my blog database and found nothing. Then I started scanning the code of the pages that Google was reporting as infected. Still nothing. I made a few changes, thinking maybe it was in error &#8211; and requested a review, then went for my ride.</p>
<p>Well, it wasn&#8217;t an error, and Google showed me a couple more pages, one of which led me directly to my <strong><a title="swfobject" href="http://code.google.com/p/swfobject/" target="_blank">swfobject</a></strong> files that had been injected with the poopy code. So off I went to download the latest version of swfobject, and to rewrite all of my static Flash pages to use the new code file. Whew. With that done, I went back in a started looking at my admin setting for the blog. I had been allowing everyone who wanted to register to do so, and come to find out, I&#8217;m guessing through a hole in <strong><a title="Wordpress" href="http://wordpress.org" target="_blank">WordPress</a></strong>, someone was able to make themselves an admin. Well, not for long, and now I&#8217;ve locked it down, and only a handful of users remain. If you were one of the folks I deleted, my apologies, please let me know and I would be more than happy to sign you up again, although you do not need to be a registered user to <strong><a title="keep up with FloggingEnglish.com" href="http://floggingenglish.com/sign-up-for-updates/" target="_blank">sign up for updates</a></strong> if that&#8217;s all you really want.</p>
<p>The final mistake I made was allowing the blog directory to be written to. This is a total n00b mistake, and I&#8217;m not sure when I did this or why &#8211; so in some respects I deserve what I got, and I&#8217;m lucky it was pretty simple to fix.</p>
<p>All in all, I&#8217;m pretty lucky it was as easy as it was to get fixed, authenticated by Google, and the malicious code warning removed. This system seems to work pretty well, and pretty quickly since all of this went down on Friday, and not weeks before. On the plus side, now I have new clean files, a more organized directory structure, updated code files for all of my javascript frameworks, and a better understanding of how to fix these things when they happen.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffloggingenglish.com%2F2010%2F08%2F08%2Freturn-from-the-3rd-level-of-malware-hell%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div class="shr-publisher-1400"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://floggingenglish.com/2010/08/08/return-from-the-3rd-level-of-malware-hell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile device support through JavaScript and CSS</title>
		<link>http://floggingenglish.com/2009/06/18/mobile-device-support-through-javascript-and-css/</link>
		<comments>http://floggingenglish.com/2009/06/18/mobile-device-support-through-javascript-and-css/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 11:01:54 +0000</pubDate>
		<dc:creator>retsoced</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[css 3]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[media queries]]></category>
		<category><![CDATA[mobile devices]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[W3C]]></category>

		<guid isPermaLink="false">http://floggingenglish.com/?p=1129</guid>
		<description><![CDATA[If you are in the business of designing, building or maintaining a website these days, you should also be concerned with making sure the maximum number of people are able to view the content on those sites. Meaning that if you aren&#8217;t doing something to support mobile web browsing than you are a bit behind [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>If you are in the business of designing, building or maintaining a website these days, you should also be concerned with making sure the maximum number of people are able to view the content on those sites. Meaning that if you aren&#8217;t doing something to support mobile web browsing than you are a bit behind the curve. It&#8217;s really an accessibility issue, not too far off from the ideas implemented in making websites accessible to people with disabilities. We&#8217;re just talking device accessibility, so let&#8217;s take a look at a couple of really simple ways to get this done.</p>
<h3>JavaScript</h3>
<p>If you go the JavaScript route, I found<strong> <a href="http://www.phpdevblog.net/2009/01/detecting-mobile-devices.html" target="_blank">this little gem</a></strong> some time ago, that covers both the client and server side detection using JavaScript and PHP. Here is<a href="http://floggingenglish.com/MobileDetection.html" target="_blank"><strong> an example page</strong></a> of what the output looks like if your detection should fail. If you are on a mobile device, the page redirects you to the root of FloggingEnglish.com. I know some older and low-end devices may not support JavaScript, but since it&#8217;s pretty freakin&#8217; ubiquitous these days, so I think it&#8217;s pretty safe. There are other JavaScript solutions out there, but this is one is clean, simple and easy to update.</p>
<p>This would be a good solution to incorporate into a Flash site as well, especially since the iPhone doesn&#8217;t support Flash yet. I know the iPhone is not the most widely used device, but that doesn&#8217;t mean you shouldn&#8217;t consider that too. With the output from the example you could place special tags or content based on the type of device, offer alternative viewing solutions for your visitors, or simply redirect to a CSS based solution for faster viewing.</p>
<h3>CSS</h3>
<p>Working a well written CSS style layout into your site is always an excellent option whether you&#8217;re primarily concerned about mobile devices or not, but with CSS 3 it&#8217;s becoming easier for developers to target mobile devices accurately and reliably. <a href="http://www.w3.org/TR/css3-mediaqueries/#media0" target="_blank"><strong>Media Queries</strong></a> are relative newcomers to the CSS scene and they are becoming more supported and in the case of Apple, the way they recommend <a title="use media queries to target css for the iPhone" href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html" target="_blank"><strong>you target the iPhone</strong></a>. They are currently Supported by all main stream browsers that are standards compliant, and supposedly IE is even on board with this one, but Opera, Safari and Firefox all support media queries.</p>
<p>So what is it then?</p>
<p style="padding-left: 30px;">&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;/includes/css/mobile/screen_320.css&#8221; type=&#8221;text/css&#8221; media=&#8221;screen and (min-device-width: 320px)&#8221;&gt;</p>
<p>Yup. That&#8217;s it. The above code would target any mobile device where the viewport measures 320px or wider, like the iPhone for example. Granted that&#8217;s a simplistic example, but you get the idea. Dean over at Bushido Designs posted a great article <a href="http://www.bushidodesigns.net/blog/mobile-device-detection-css-without-user-agent/" target="_blank"><strong>Bulletproof Mobile device detection</strong></a>. In fact that example doesn&#8217;t really convey the strengths of media queries and how flexible this method really is. If you take a look at <a href="http://www.w3.org/TR/css3-mediaqueries/#media1" target="_blank"><strong>the W3C recommendation</strong></a>, you will see the following features:</p>
<ul>
<li>width</li>
<li>height</li>
<li>device-width</li>
<li>device-height</li>
<li>orientation</li>
<li>aspect ratio</li>
<li>device-aspect-ratio</li>
<li>color</li>
<li>color-index</li>
<li>monchrome</li>
<li>resolution</li>
<li>scan</li>
<li>grid</li>
</ul>
<p>So you can begin to see the strengths of this method and how it could be the key to blissful mobile CSS support. Using the color feature for example would allow you target a specific stylesheet for devices capable of rendering in color, while using aspect-ration you could target 16:9 devices as well, like the <a href="http://www.us.playstation.com/PSP" target="_blank"><strong>PSP </strong></a>(480 x 272).</p>
<p>Of course none of this would be an issue if Apple and Opera hadn&#8217;t decided to ignore the <a href="http://www.w3.org/TR/CSS2/media.html#media-intro" target="_blank"><strong>handheld media type</strong></a> with their mobile browsers. With the two biggest mobile browsers off the tabel, that pretty much renders the use of handheld useless. A move that is decidedly Microsoft-esque.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffloggingenglish.com%2F2009%2F06%2F18%2Fmobile-device-support-through-javascript-and-css%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div class="shr-publisher-1129"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://floggingenglish.com/2009/06/18/mobile-device-support-through-javascript-and-css/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test your site for IE goodness with IE Tester</title>
		<link>http://floggingenglish.com/2008/09/22/test-your-site-for-ie-goodness-with-ie-tester/</link>
		<comments>http://floggingenglish.com/2008/09/22/test-your-site-for-ie-goodness-with-ie-tester/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 01:16:13 +0000</pubDate>
		<dc:creator>retsoced</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE 8]]></category>
		<category><![CDATA[IE Tester]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[multiple versions of IE]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.floggingenglish.com/?p=646</guid>
		<description><![CDATA[Looking for a functional way to get IE 8 and IE 7 to run on my machine today, I found the IE Tester project, and I have to say that for an all in one IE testing app, it works quite well. Up until today the only tool I had at my disposal was Multiple [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img src="/media/contentMedia/2008/09/ie7.jpg" alt="Internet Explorer" title="Internet Explorer" width="125" height="126" align="right" />Looking for a functional way to get IE 8 and IE 7 to run on my machine today, I found <a href="http://www.my-debugbar.com/wiki/IETester/HomePage" title="IE Tester" target="_blank"><strong>the IE Tester project</strong></a>, and I have to say that for an all in one IE testing app, it works quite well. Up until today the only tool I had at my disposal was <a href="http://tredosoft.com/Multiple_IE" target="_blank"><strong>Multiple IEs from TredoSoft</strong></a> and the biggest limitation here is that it doesn&#39;t incorporate 7 or the 8 beta (1 or 2); which IE Tester does. Since IE 8 is due out this quarter (I think) it is absolutely imperative that devs start testing (if they haven&#39;t already) for this new wonderful application to see how it destroys, or interacts with the web. For more detail on what the IE team is doing with version 8, check the <a href="http://blogs.msdn.com/ie/" title="IE Blog" target="_blank"><strong>IE Blog</strong></a>.</p>
<p>The biggest benefit to IE Tester so far is that it can be installed along side all of your other browsers (including Multiple IEs), unlike the frustrating paradigm that Microsoft operates under of not allowing multiple versions of IE installed on a single desktop. Instead they say you should test using Virtual PC and load up separate version of the OS virtually &#8211; yeah&#8230;. that&#39;s a lot better than just opening a browser. </p>
<p>Working with IE 8 so far I have found a lot of the expected CSS weirdness but above that I have also found that the <a href="http://software.xfx.net/utilities/dmbuilder/" target="_blank"><strong>xFx JumpStart DHTML Menu Builder</strong></a> menus fail irrecoverably, and since there is <a href="http://software.xfx.net/uboards/forums/index.php?s=0f5f275c14584871bff2e25c314b21dd&amp;showtopic=4636" target="_blank"><strong>an open thread posted in May</strong></a> with no replies, I have a very low confidence threshold that anyone cares enough to fix it. This is bothersome simply because I have sites that use this menu, and now I am forced to find alternative solutions since a wait-and-see mentality doesn&#39;t really work for me.</p>
<p><a href="http://www.microsoft.com/windows/internet-explorer/beta/default.aspx" title="IE 8" target="_blank"><strong>IE 8 has a compelling list of new features</strong></a> and standards oriented enhancements, being a quantum leap in the right direction for the kings of the one-way road. Continually having to go to battle to get everything to work across 5 browsers and something like almost 8 versions is a bit tiresome and far more complicated than necessary. I still get a ton of hits from IE 6 users both here and my day-job sites, which I mainly attribute to the <a href="http://reviews.cnet.com/browsers/internet-explorer-7/4505-3514_7-32111537.html" target="_blank"><strong>bad press IE 7 received</strong></a> after launch &#8211; much in the same way Vista has gotten vilified. People and corporations have made the flawed decision to <em>not </em>migrate to IE 7 under some false ideology that they are better off with 6, never mind the gaping security holes and out dated rendering engines. </p>
<p>Okay, so I getting off topic&#8230; again. Since I have to find a new menu anyway, I am compiling a list of AJAX menus to replace the DHTML menu, so once I have that worked out I will post that list here &#8211; in the meantime test your sites with <a href="http://www.my-debugbar.com/wiki/IETester/HomePage" target="_blank"><strong>IE Tester</strong></a>. </p>
<p>&nbsp;</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffloggingenglish.com%2F2008%2F09%2F22%2Ftest-your-site-for-ie-goodness-with-ie-tester%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div class="shr-publisher-646"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://floggingenglish.com/2008/09/22/test-your-site-for-ie-goodness-with-ie-tester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy source code with JavaScript and Flash</title>
		<link>http://floggingenglish.com/2008/04/17/copy-source-code-with-javascript-and-flash/</link>
		<comments>http://floggingenglish.com/2008/04/17/copy-source-code-with-javascript-and-flash/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 03:44:10 +0000</pubDate>
		<dc:creator>retsoced</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[flashFoo]]></category>
		<category><![CDATA[code sample]]></category>
		<category><![CDATA[copy to clipboard]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[innerHTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[source files]]></category>
		<category><![CDATA[swf]]></category>
		<category><![CDATA[system class]]></category>

		<guid isPermaLink="false">http://www.floggingenglish.com/?p=463</guid>
		<description><![CDATA[My latest project to go into production is a retail targeted newsletter site designed to deliver content both on the site itself and, naturally, through a newsletter to the subscribed members. As a little background, the site has a custom-built CMS managing 90% of all of the content, including every issue of the newsletter and [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>My latest project to go into production is a retail targeted newsletter site designed to deliver content both on the site itself and, naturally, through a newsletter to the subscribed members. As a little background, the site has a custom-built CMS managing 90% of all of the content, including every issue of the newsletter and all of the contained articles. One of the obstacles that I needed to overcome was a way to easy way to get the dynamic content from the database into a seperate mass email application fo delivery. This sounded pretty simple, so I saved it until last.</p>
<p>After a bit of searching, I found information about Firefox and Opera having security measures preventing this from working right out of the gate. Okay, but I know sites like Google, Amazon, and countless others have pulled this off &#8211; so I know it&#39;s possible. My criteria was pretty simple:</p>
<blockquote><p>copy the source code of a &lt;div&gt; that wrapped the essential content to the clipboard by clicking a button.</p></blockquote>
<p>That&#39;s it; nothing too fancy. The next thing I found was an example of <a href="http://www.jeffothy.com/weblog/clipboard-copy/" title="clipboard copy" target="_blank"><strong>pulling text from a textfield on Jeffothy&#39;s Keyings</strong></a> blog. I didn&#39;t have content in a textbox though, it was in a &lt;div&gt; &#8211; so I altered the code to pull the data using innerHTML.</p>
<blockquote><p>document.getElementById(&#39;sourceDiv&#39;).innerHTML;</p>
</blockquote>
<p>That resulted in <em>undefined </em>being copied to the clipboard (I&#39;m still not sure why). So back to Google to find some .net examples, but they turned out to be far more complex than what I wanted to use. I knew I could do it with JavaScript though; so I went back the first example. First, I simply set up a function to grab the code and fire an alert.</p>
<blockquote><p>&lt;script language=&quot;javascript&quot;&gt;<br />&nbsp;&nbsp;&nbsp; function getSource() {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var sourceData= document.getElementById(&#39;sourceDiv&#39;).innerHTML;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  alert(sourceData);</p>
<p>&nbsp;&nbsp;&nbsp; }<br />&lt;/script&gt;</p>
</blockquote>
<p>&nbsp;This worked fine. So the next part was to get it to the clipboard, but I kept running into not being able to pass it to the clipboard function I downloaded from Jeffothy&#39;s site &#8211; so I added a textarea, and set <strong>style display:none</strong>. Then copied the code out of the textarea onto the clipboard and viola!</p>
<p>But not quite. IE doesn&#39;t like the textarea set to not visible and wouldn&#39;t <em>recognize </em>it being there at all (throwing a JavaScript error), so I had to change the style to width:1px and height:1px to get it work cross browsers.&nbsp;</p>
<blockquote><p>&lt;script type=&quot;text/javascript&quot;&gt;<br />&nbsp;&nbsp;&nbsp; function copySource(inElement) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (inElement.createTextRange) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var range = inElement.createTextRange();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (range)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; range.execCommand(&#39;Copy&#39;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var flashcopier = &#39;flashcopier&#39;;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(!document.getElementById(flashcopier)) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var divholder = document.createElement(&#39;div&#39;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; divholder.id = flashcopier;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.body.appendChild(divholder);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.getElementById(flashcopier).innerHTML = &#39;&#39;;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var divinfo = &#39;&lt;embed src=&quot;/media/_clipboard.swf&quot; FlashVars=&quot;clipboard=&#39;+escape(inElement.value)+&#39;&quot; width=&quot;0&quot; height=&quot;0&quot; type=&quot;application/x-shockwave-flash&quot;&gt;&lt;/embed&gt;&#39;;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.getElementById(flashcopier).innerHTML = divinfo;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>&nbsp;&nbsp;&nbsp; function getSource() {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var sourceData = document.getElementById(&#39;sourceDiv&#39;).innerHTML;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.getElementById(&quot;sourceField&quot;).value = sourceData;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; copySource(document.getElementById(&quot;sourceField&quot;));<br />&nbsp;&nbsp;&nbsp; }<br />&lt;/script&gt; </p>
</blockquote>
<p>Now the interesting part about this is the swf file. It is the key to getting this whole deal to work. By using the _clipboard.swf file (originally built by Mark O&rsquo;Sullivan of <a href="http://lussumo.com/">http://lussumo.com/</a>), you are able to get the copied code out of the browser and onto the clipboard by passing it to Flash&#39;s <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000325.html" title="System class in AS 3" target="_blank"><strong>System class</strong></a> using the setClipboard method. Pretty ingenious really.</p>
<p>All you have to do now is just drop a form in the page around everything you want to copy, and a button and textarea.</p>
<blockquote><p>&lt;center&gt;<br />&nbsp;&nbsp;&nbsp; &lt;input type=&quot;button&quot; value=&quot;:: Copy to the clipboard&nbsp; ::&quot; onclick=&quot;getSource()&quot; /&gt;<br />&lt;/center&gt;<br />&lt;br /&gt;<br />&lt;textarea name=&quot;sourceField&quot; id=&quot;sourceField&quot; cols=&quot;85&quot; rows=&quot;10&quot; readonly=&quot;readonly&quot; style=&quot;width:1px;height:1px;&quot;&gt;&lt;/textarea&gt;</p>
</blockquote>
<p>&nbsp;I<strong> <a href="http://www.floggingenglish.com/media/contentMedia/2008/04/copy_to_clipboard.zip" title="source file" target="_blank">wrapped it all up in a zip file</a></strong> for those who want to download it.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffloggingenglish.com%2F2008%2F04%2F17%2Fcopy-source-code-with-javascript-and-flash%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div class="shr-publisher-463"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://floggingenglish.com/2008/04/17/copy-source-code-with-javascript-and-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

