Posts Tagged ‘Web Development’

Valid Flash Embed and Preloaders Episode V: Internet Explorer Strikes Back

If you saw my previous post on valid Flash embed while maintaining preload functionality and used it, be warned: when the user does not have Flash, a lovely <![endif]--> will appear in IE where the Flash movie would normally be. The only way around it I’ve found is to actually duplicate everything from the opening object tag to the closing one so there is one each for IE and Firefox. For example:

<!--[if !IE]>-->
<object data="movie.swf" type="application/x-shockwave-flash" width="725" height="235">
	<param name="movie" value="movie.swf" />
</object>
<!--<![endif]-->
<!--[if IE]>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="725" height="235">
	<param name="movie" value="movie.swf" />
</object>
<![endif]-->

Definitely a pain, but I’ve found no other way around it.

Also in my search for a solution, I discovered that our old pal Internet Explorer does not let you append anything but param elements to object elements in Javascript. That was pretty frustrating. Don’t try that. It doesn’t work.

—Kyle Blizzard

The Pesky iframe and XHTML Strict

Update: Example code updated. It used the shortened form of iframe before, as in <iframe />. That doesn’t sit well with IE. It now uses <iframe></iframe> which works. The same goes for object. It similarly does not play well with Firefox 4 (perhaps even lower versions) in shortened form.

If you’ve done much web work before, you’ve probably, at some time or another, had to use an iframe. It’s not pretty, but sometimes it’s the only choice, such as embedding a widget from another site or displaying things such as real estate listings. One of my biggest problems with it is that it doesn’t exist in the spec for XHTML Strict! It exists in Transitional, but I don’t like to use it. That may be good enough for some developers, but certainly not for me. How about you?

In Internet Explorer 8 (and possibly IE7, but I have not tested it) and Firefox, you can use the object element to embed a web page just like an iframe; however, IE gives it a thick, lovely border that seems impossible to remove. Here’s the trick: employing IE’s conditional comments, use an iframe for IE and an object for everything else. Here’s an example:

<!--[if !IE]><!--><object data="http://www.blizzarddigital.com/blog/" type="text/html" width="320" height="240"></object>
	<!--<![endif]-->
<!--[if IE]><iframe frameborder="0" src="http://www.blizzarddigital.com/blog/" width="320" height="240"></iframe>
	<![endif]-->

Valid XHTML Strict! Make sure to keep your settings the same across both elements to keep it consistent.

Happy coding!

—Kyle Blizzard

Valid Flash Embed and Preloaders in Internet Explorer

Hello once again, web friends. Today I bring tidings of Flash preloaders and validity.

You may have noticed that with the embed code from my YouTube article that Flash movie preloaders don’t work in Internet Explorer, and the movie has to load entirely before it even displays at all. This is because Internet Explorer requires a different attribute and the removal of another in the object tag to let preloaders work properly. However, with different attributes, the Flash movie will not display at all in Firefox, so we must use Internet Explorer’s conditional comments to utilize two different opening object tags. Behold:

<!--[if !IE]>--><object data="yourmovie.swf" type="application/x-shockwave-flash"
	width="320" height="240"><!--<![endif]-->
<!--[if IE]><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	width="320" height="240"><![endif]-->
	<param name="movie" value="yourmovie.swf" />
	<param name="quality" value="high" />
</object>

The first line is the original that works in both IE and Firefox but doesn’t allow preloaders in IE. The second is the IE-only method that works with preloaders. Note the lack of a data attribute and the addition of a classid attribute.

Well, there you have it. Venture forth and embed Flash validly with preload animations!

—Kyle Blizzard

The img Element Vs the CSS background-image Property

Don’t know when to use the img element or when to use the CSS background-image property? Don’t fret; there is hope. Read further and all shall be revealed.

The img element is best used for pictures that are completely unrelated to the stylesheet. That is, pictures that would need to display no matter how much the look of the site changes. These would be pictures related to a news article or photos in a gallery.

The CSS background-image property is for images that make up the appearance of the stylesheet. These pictures on one stylesheet would be different or just completely absent on another stylesheet. They don’t add to the content of the page in any way and are only there to give the page its “look”. These image files would be stored in the stylesheet’s images folder. (See my last post for more on this.)

Just another tip from your uncle Kyle!

—Kyle Blizzard

Organizing Your CSS Files

When I create a web site, I like to organize my stylesheets and images into a specific folder structure. It keeps things tidy and separates presentation files (stylesheets and images) from content files (pages and images related to the content). It also leaves room for additional stylesheet “themes” for your site.

Here is an example of this folder structure:

/styles/
/styles/default/
/styles/default/images/

Default in this example would be the name of the “theme”. The sites I develop typically do not have multiple themes for the user to pick, so I don’t usually take the time to give them fancy names. However, if your site utilizes multiple stylesheets that the user could choose from (such as at the CSS Zen Garden), creative names would be helpful.

All stylesheets for the Default theme would be placed in the /styles/default/ folder. Likewise, images used by those stylesheets would go in the /styles/default/images/ folder.

This method keeps your styles consolidated and makes it easy to use them across multiple sites. All you need to do is copy the folder to the other site; you don’t need to pick through the images folder and figure out which ones are used by the stylesheet and which ones aren’t.

Technically, you wouldn’t even need to copy anything to another site. You could just specify the full URL in the link element or @import rule on the page, but I urge you not to do this. Your visitors may be using security software that sees cross-site references as malicious, thus blocking the stylesheet from downloading or, worse, blocking the entire page.

—Kyle Blizzard