Unobtrusive iFrame with JQuery

I couldn’t find a great way to do an iframe in an xhtml site and stil maintain accessibility - until I came across malsup’s media plugins. They basically create a link to the swf, mp3, or quicktime and replace the link with the content via a custom class on the href tag.

So, I figured, what a great way to do an iframe, too. Something like:

<a href="myiframe.html" class="iframe">Iframe Content</a>

I passed along the idea to my programming genius, Vlada and he came up with a great jquery iframe plugin by modifying malsup’s swf plugin.

<a href="http://33rockers.com" class="iframe w:700 h:300" >Iframe Content</a>

makes this…

<div class=iframe><iframe id=content_iframe marginWidth=0 marginHeight=0 src="http://33rockers.com/" frameBorder=0 width=640 height=480></iframe></div>

You can also set the defaults in jquery_iframe.js and just use
<a href="http://33rockers.com" class="iframe" >Iframe Content</a>

If javascript is turned off, it will just show a link to the content.

Here is the code in action and u can download the source code here.


About this entry