<?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>Webdevelopment at huuah.com &#187; iframe</title>
	<atom:link href="http://huuah.com/tag/iframe/feed/" rel="self" type="application/rss+xml" />
	<link>http://huuah.com</link>
	<description>webdevelopment, cms, php, javascript etc</description>
	<lastBuildDate>Sat, 04 Sep 2010 22:55:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>jQuery and iframe manipulation</title>
		<link>http://huuah.com/jquery-and-iframe-manipulation/</link>
		<comments>http://huuah.com/jquery-and-iframe-manipulation/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 10:52:48 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[iframe]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=248</guid>
		<description><![CDATA[<p>I&#8217;ve been experimenting with some iframe-manipulation with jQuery, but this was not as easy as I have hoped for. There is not much help on jquery.com and a Google search just found others with the same kind of problem.</p>
<p>My setup is very basic. An iframe loading a page like&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been experimenting with some iframe-manipulation with jQuery, but this was not as easy as I have hoped for. There is not much help on jquery.com and a Google search just found others with the same kind of problem.</p>
<p>My setup is very basic. An iframe loading a page like this </p>
<pre class="brush: xml;">&lt;iframe name=&quot;framename&quot; id=&quot;myframe&quot; src=&quot;mypage.html&quot;&gt;&lt;/iframe&gt;</pre>
<p>In the page where this iframe is being loaded, I have included the jquery.min.js and an extra .js-file for my code.</p>
<div class="bt">
<script type="text/javascript"><!--
amazon_ad_tag="huuah-21"; 
amazon_ad_width="468"; 
amazon_ad_height="60"; 
amazon_color_background="F5F5F5"; 
amazon_color_border="337696"; 
amazon_color_logo="FFFFFF"; 
amazon_color_link="0088CC"; 
amazon_ad_logo="hide"; 
amazon_ad_link_target="new"; 
amazon_ad_title="jQuery Book"; //--></script><br />
<script type="text/javascript" src="http://www.assoc-amazon.co.uk/s/asw.js"></script>
</div>
<p><strong>First attempt</strong> was to try the examples found on Google. For testing purposes I wanted to set a red background color on every &lt;div&gt; inside the iframe.</p>
<pre class="brush: jscript;">var frame = $(&quot;#myframe&quot;)[0].contentDocument;
$(&quot;div&quot;, frame).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>Nothing happens.</p>
<p>When testing new things I often use alert-boxes for test-output, so I tried inserting an alert-box:</p>
<pre class="brush: jscript; highlight: [1];">alert(&quot;trying a red color&quot;);
var frame = $(&quot;#myframe&quot;)[0].contentDocument;
$(&quot;div&quot;, frame).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>And hey! When pushing the alert-box, the divs inside the iframe gets a red background-color. Or at least they do in Firefox 3.0.11 (still a no-go in IE8). Strange.</p>
<p><strong>Test 2</strong>:</p>
<pre class="brush: jscript;">$(&quot;#myframe&quot;).contents().find(&quot;div&quot;).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>Nothing! Blank!</p>
<p>Oh well. Why not try the alert-box again:</p>
<pre class="brush: jscript; highlight: [1];">alert(&quot;trying a red color&quot;);
$(&quot;#myframe&quot;).contents().find(&quot;div&quot;).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>Hmm.. this seems to work in both Firefox 3.0.11 and Internet Explorer 8 <strong>IF</strong> you <strong>don&#8217;t</strong> push the alert-box until the iframe is finished loading.</p>
<p>So perhaps it&#8217;s all about not accessing the iframe before the contents has been loaded. So I tried wrapping the whole thing in a ready-function like this:</p>
<pre class="brush: jscript;">$(&quot;#myframe&quot;).ready(function () {
...
}</pre>
<p>That did <strong>not</strong> help at all. </p>
<p>Well. Google google google. And bingo. There&#8217;s a plugin for jQuery called <a href="http://ideamill.synaptrixgroup.com/wp-trackback.php?p=6">frameReady</a> and this does the trick.</p>
<div class="ww">
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1430230541?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430230541"><img border="0" src="/512a8p3m4KL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430230541" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0596101694?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0596101694"><img border="0" src="/415wDIPoM8L._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0596101694" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0240813286?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0240813286"><img border="0" src="/515T2pj0xRL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0240813286" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1935182323?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1935182323"><img border="0" src="/51Mz3glo-7L._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1935182323" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0596101996?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0596101996"><img border="0" src="/51IJ8LZqxmL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0596101996" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
</div>
<p><strong>Third and final test</strong>:<br />
Include the jQuery.frameReady.js in the main page and enter this code:</p>
<pre class="brush: jscript;">$.frameReady( function() {
    $(&quot;div&quot;).css(&quot;background&quot;, &quot;red&quot;);
  },
  &quot;framename&quot;
);</pre>
<p>This loads the iframe and sets a red background color on every div inside the iframe. Tested in IE8 and Firefox 3.0.11.</p>
<p><strong>Conclusion</strong>:<br />
Use the <a href="http://ideamill.synaptrixgroup.com/wp-trackback.php?p=6">frameReady</a> plugin for jQuery when manipulating with iframes.</p>
<p>Update: If you&#8217;re having trouble getting this to work, please check the source code for frameReady and verify that the hardcoded path for /js/jQuery.js matches your site configuration!</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/jquery-and-iframe-manipulation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
