<?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>Cameron McKay &#187; ie</title>
	<atom:link href="http://cdmckay.org/blog/tag/ie/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdmckay.org/blog</link>
	<description>Programming and Game Development</description>
	<lastBuildDate>Mon, 14 May 2012 21:11:58 +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>How to (kinda) fix Firefox&#8217;s showModalDialog</title>
		<link>http://cdmckay.org/blog/2009/07/07/how-to-kinda-fix-firefoxs-showmodaldialog/</link>
		<comments>http://cdmckay.org/blog/2009/07/07/how-to-kinda-fix-firefoxs-showmodaldialog/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 18:48:38 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[showmodaldialog]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=738</guid>
		<description><![CDATA[As someone who has had to write a lot of IE-only code (against my will, I swear!), I was pleased to hear that Firefox 3.0 added support for the IE JavaScript function window.showModalDialog. Being in the middle of re-writing an IE-only web application, I thought this would simplify rewriting the modal dialogs to be compatible [...]]]></description>
			<content:encoded><![CDATA[<p>As someone who has had to write a lot of IE-only code (against my will, I swear!), I was pleased to hear that Firefox 3.0 added support for the IE JavaScript function <code>window.showModalDialog</code>.  Being in the middle of re-writing an IE-only web application, I thought this would simplify rewriting the modal dialogs to be compatible with both browsers.</p>
<p>Unfortunately, I don&#8217;t think the folks at Mozilla put their best effort into this one.  </p>
<p><span id="more-738"></span></p>
<p>First of all, the Firefox implementation only supports a subset of the IE options.  Here&#8217;s a table showing what each browsers implementation supports according to their documentation:</p>
<table>
<tr>
<th colspan="3">Documented Support</th>
</tr>
<tr>
<th>Option</th>
<th><a href="http://msdn.microsoft.com/en-us/library/ms536759%28VS.85%29.aspx">Internet Explorer</a></th>
<th><a href="https://developer.mozilla.org/En/DOM/Window.showModalDialog">Firefox</a></th>
</tr>
<tr>
<td>dialogWidth</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogHeight</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogLeft</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogTop</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>center</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogHide</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>edge</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>resizable</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>scroll</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>status</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>unadorned</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
</table>
<p>Doesn&#8217;t seem too bad, right?  We still have <code>center</code>, <code>resizable</code> and <code>scroll</code> right? Right? <em>Wrong.</em> </p>
<h3>Documentation != Implementation</h3>
<p>It seems the guys who wrote the Firefox documentation weren&#8217;t the same guys who wrote the code. Including <code>center</code>, <code>resizable</code> or <code>scroll</code> in your arguments string has no effect whatsoever.  In fact, <code>center</code> is supposed to be <code>on</code> by default, but I can tell you right now that the modal dialog sure as hell isn&#8217;t centered.</p>
<p>Here&#8217;s an updated support matrix:</p>
<table>
<tr>
<th colspan="3">Actual Support</th>
</tr>
<tr>
<th>Option</th>
<th>Internet Explorer</th>
<th>Firefox</th>
</tr>
<tr>
<td>dialogWidth</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogHeight</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogLeft</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogTop</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>center</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>dialogHide</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>edge</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>resizable</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>scroll</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>status</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>unadorned</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
</table>
<p>Fortunately, they did get one part right: the dialog is modal.  Woooo!</p>
<h3>Can we fix it?</h3>
<p>Well, we can, kinda.  We can&#8217;t fix <code>resizable</code>, because that&#8217;s a property of the window, and we can&#8217;t fix <code>scroll</code> for the same reason.  We can, however, emulate the <code>center</code> option by using <code>dialogLeft</code> and <code>dialogTop</code>.  Here&#8217;s some quick-and-dirty code I wrote to do that.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> oldShowModalDialog <span style="color: #339933;">=</span> window.<span style="color: #660066;">showModalDialog</span><span style="color: #339933;">;</span>
window.<span style="color: #660066;">showModalDialog</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> args<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>           
  <span style="color: #006600; font-style: italic;">// Convert the options string into an object.</span>
  <span style="color: #003366; font-weight: bold;">var</span> pairs <span style="color: #339933;">=</span> options.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s+/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> option <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>pairs<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> pair <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pair.<span style="color: #660066;">length</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    option<span style="color: #009900;">&#91;</span>pair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Get the width and height of the document.</span>
  <span style="color: #003366; font-weight: bold;">var</span> width <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> height <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Get the width and height of the dialog.</span>
  <span style="color: #003366; font-weight: bold;">var</span> dialogWidth <span style="color: #339933;">=</span> option.<span style="color: #660066;">dialogWidth</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #003366; font-weight: bold;">var</span> dialogHeight <span style="color: #339933;">=</span> option.<span style="color: #660066;">dialogHeight</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Calculate where the dialog needs to be to be</span>
  <span style="color: #006600; font-style: italic;">// centered.</span>
  <span style="color: #003366; font-weight: bold;">var</span> dialogLeft <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>width <span style="color: #339933;">-</span> dialogWidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> dialogTop <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>height <span style="color: #339933;">-</span> dialogHeight<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Add those settings to the options string.</span>
  options <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;dialogLeft: &quot;</span> <span style="color: #339933;">+</span> dialogLeft <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;; &quot;</span><span style="color: #339933;">;</span>
  options <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;dialogTop: &quot;</span> <span style="color: #339933;">+</span> dialogTop <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;; &quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Call the original function.</span>
  <span style="color: #000066; font-weight: bold;">return</span> oldShowModalDialog<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> args<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Although this code uses <a href="http://jquery.com">jQuery</a>, you could easily rewrite it to use vanilla JavaScript.</p>
<h3>Will it be fixed soon?</h3>
<p>Firefox has had <code>showModalDialog</code> since 3.0.  So naturally, you&#8217;d have assumed they&#8217;d have fixed this bug in 3.5, right?  Nope!  The bug still exists in 3.5.  Thus, I wouldn&#8217;t hold my breath on this one being fixed anytime soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/07/how-to-kinda-fix-firefoxs-showmodaldialog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making tables print pretty in IE, part 2</title>
		<link>http://cdmckay.org/blog/2009/01/29/making-tables-print-pretty-in-ie-part-2/</link>
		<comments>http://cdmckay.org/blog/2009/01/29/making-tables-print-pretty-in-ie-part-2/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 23:00:52 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[printing]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=29</guid>
		<description><![CDATA[In my last post, I mentioned that I had come up with a way to prevent tables in Internet Explorer 6 and 7 from looking like this. In this post, I&#8217;ll show you how to do it. (Disclaimer: This method has been found to break if the a cell has a line break in it [...]]]></description>
			<content:encoded><![CDATA[<p>In my last <a href="http://cdmckay.org/blog/2009/01/28/making-tables-print-pretty-in-ie/">post</a>, I mentioned that I had come up with a way to prevent tables in Internet Explorer 6 and 7 from looking like <a href="http://www.xefteri.com/articles/content/26/images/table_footer_issue.gif" rel="lightbox[29]">this</a>.  In this post, I&#8217;ll show you how to do it.</p>
<p><strong>(Disclaimer: This method has been found to break if the a cell has a line break in it or is wrapped to a second line).</strong></p>
<p><span id="more-29"></span></p>
<p>First, let&#8217;s start with an example table:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;example-table&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Client #<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Joe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Shmoe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>123451<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Joe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Shmoe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>123451<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Joe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Shmoe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>123451<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Joe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Shmoe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>123451<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Repeat these many times to make it go to a second page. --&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></div></div>

<p>Add a stylesheet like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#example-table</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#example-table</span> th<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#example-table</span> td
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>If you repeat those rows enough times you can get the graphical glitch mentioned above.  Now, to fix it, what we&#8217;ll do is add a <code>&lt;div&gt;</code> tag to every cell and then make it provide the side borders.</p>
<p>So first, we&#8217;ll modify the table as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;example-table&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Client #<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell&quot;</span>&gt;</span>Joe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell&quot;</span>&gt;</span>Shmoe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;last-col&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell&quot;</span>&gt;</span>123451<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>    
    <span style="color: #808080; font-style: italic;">&lt;!-- Repeat this many times to make it go to a second page. --&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></div></div>

<p>What we&#8217;ve done here is added a <code>&lt;div&gt;</code> to each cell and given these <code>&lt;div&gt;</code>&#8216;s a class called <code>cell</code>.  This is so we can do stuff to them in our CSS stylesheet.  We&#8217;ve also given the last cell in each row the class <code>last-col</code>.  This is so we can identify the last column of each row.  The reasoning for this will be explained shortly.</p>
<p>Now, as I&#8217;ve said, our goal here is to replace the <code>table</code>-provided vertical borders (the | ones) with the <code>div</code>-provided ones.  So we need to modify the stylesheet to reflect that:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#example-table</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#example-table</span> th<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#example-table</span> td
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>There&#8217;s also an issue of padding.  By default, tables are slightly padded, which is fine for most circumstances.  However, in this case, padding would be counterproductive, it would prevent the <code>div</code>&#8216;s border from matching up with the <code>table</code>&#8216;s border.  So that&#8217;ll have to be changed:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#example-table</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#example-table</span> th<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#example-table</span> td
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Time for some <code>div</code> styling.  Since the <code>div</code> is our new cell, we need to style it as such.  First thing, let&#8217;s make the <code>div</code> provide us with sides.  Now, we could do something like <code>border-left: 1px black solid; border-right: 1px black solid;</code>.  This would look fine, except that all the vertical borders in the middle of the table would 2 pixels wide (think about it).  So, instead, we&#8217;ll make all the <code>div</code> cells provide borders on the left side, except for the last column, which&#8217;ll provide borders on both sides (hence the purpose of the <code>last-col</code> class).</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.cell</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#example-table</span> <span style="color: #6666ff;">.last-col</span> div<span style="color: #6666ff;">.cell</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We also need to add back the padding we stripped out from the table <code>td</code> tags:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.cell</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#example-table</span> <span style="color: #6666ff;">.last-col</span> div<span style="color: #6666ff;">.cell</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>And there you have it.  Now when you load up print preview, your tables should look pretty.  Here&#8217;s the final stylesheet in case you got lost:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* So the headers will display on every page. */</span>
thead <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">table-header-group</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Make table only provides vertical border. */</span>
<span style="color: #cc00cc;">#example-table</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* 
 * Make header and normal cells only show top and bottom border,
 * and remove all padding so the div lines will match up with the table.
 */</span>
<span style="color: #cc00cc;">#example-table</span> th<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#example-table</span> td
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Make the div cell only provide the left border, and simulate table padding. */</span>
div<span style="color: #6666ff;">.cell</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Provide the right border in the last column. */</span>
<span style="color: #cc00cc;">#example-table</span> <span style="color: #6666ff;">.last-col</span> div<span style="color: #6666ff;">.cell</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #000000; font-weight: bold;">black</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/01/29/making-tables-print-pretty-in-ie-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making tables print pretty in IE, part 1</title>
		<link>http://cdmckay.org/blog/2009/01/28/making-tables-print-pretty-in-ie/</link>
		<comments>http://cdmckay.org/blog/2009/01/28/making-tables-print-pretty-in-ie/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:03:54 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[printing]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=17</guid>
		<description><![CDATA[So I&#8217;m currently doing a side job developing a web application to help pay for Wezzle and, y&#8217;know, food and shelter. Basically, I&#8217;m making a system that displays tables grabbed from an Oracle database using elaborate queries.  That&#8217;s the easy part.  These tables need to be printed out.  That&#8217;s the hard part. We&#8217;ll talk about [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m currently doing a side job developing a web application to help pay for Wezzle and, y&#8217;know, food and shelter.</p>
<p>Basically, I&#8217;m making a system that displays tables grabbed from an Oracle database using elaborate queries.  That&#8217;s the easy part.  These tables need to be printed out.  That&#8217;s the hard part.  We&#8217;ll talk about that here, specifically in relation to IE7 (the hacks here might not work for Firefox or Chrome).</p>
<p><strong>(Disclaimer: This method has been found to break if the a cell has a line break in it or is wrapped to a second line).</strong></p>
<p><span id="more-17"></span></p>
<p>CSS has a mechanism for handling printing.  When we link in a stylesheet with the <code>&lt;link&gt;</code> tag, we have the option to set an attribute for its media type.</p>
<p>For example, here&#8217;s an HTML snippet that would define two stylesheets:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;styles/style.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;print&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;styles/style.print.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>The main thing to notice here is that <code>media='screen'</code> is the stylesheet for the browser, and <code>media='print'</code> is the stylesheet for the printer.</p>
<p>Why is this useful? Well, typically there are many things we want to show in a browser window but we don&#8217;t want to print on a page.  If we&#8217;re going to print a table (and only a table) we&#8217;ll need to hide our navigation bar, buttons, and rotating skull <code>.gifs</code>. To do that, we need to go through our print stylesheet and add in <code>display='none'</code> for all the elements that we don&#8217;t want shown.</p>
<p>Once we&#8217;ve hidden all the non-table elements, it&#8217;s time to see how our page would look printed.  So we load up print preview and <a href="http://www.xefteri.com/articles/content/26/images/base_table.gif" rel="lightbox[17]">take a look</a>.  Ugh, the table headers show only on the first page, but not on the ensuing pages (example ), even though we&#8217;re using the <code>&lt;thead&gt;</code> tag.  Fortunately for us, this is easily corrected with the following CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">thead <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">table-header-group</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>With the heading problem fixed, we look again at the print preview.  Everything looks a lot nicer, except for  this really <a href="http://www.xefteri.com/articles/content/26/images/table_footer_issue.gif" rel="lightbox[17]">ugly looking graphical problem</a> with multi-page tables.  One solution, suggested by <a href="http://www.xefteri.com/articles/show.cfm?id=26">Xefteri</a>, is to do away with the vertical lines in your table.</p>
<p>I don&#8217;t think that&#8217;s good enough.  So I came up with a better (albeit slower) solution using <code>&lt;div&gt;</code> tags within each of the cells and using them to put the vertical lines into the table.  This will be explained in further detail in a future post.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/01/28/making-tables-print-pretty-in-ie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

