Featured Posts

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Flex Assets/File Manager – ASP VBScript - Version... I recently built a JavaScript file manager but I wanted more control and better usability instead of expanding on the JavaScript version I decided to build it using Flex....

Readmore

Getting at your SQL Database using Flex and .NET Web ServicesGetting at your SQL Database using Flex and .NET Web... So you gave up on trying to figure out how you can directly connect Flex to your database like with any server side language and decided to Google the answer. Well by now...

Readmore

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Fitchett Rss

Resize IFRAME Based on Content – Cross Domain

Posted on : 30-04-2009 | By : Michael Fitchett | In : HTML, JavaScript

3

windowYou will find a lot on this topic but no real solid answers. I looked around and ended up piecing this solution together. Yes that’s right it CAN be done! Well sorta…

Put this in between your <HEAD> tags or in your scripts include file

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<script type="text/javascript">
//Lookup Cookie by Name and Return Value
function readCookie(name) {
	var nameEQ = name + &quot;=&quot;;
	var ca = document.cookie.split(';');
	for(var i=0;i &lt; ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
 
//Set iFrame Height based on &quot;kofax-iframe-height&quot; value
function setIFrameHeightToCookie(cookieValue)
{
	var formHeight = readCookie(cookieValue);
	var iFrame = document.getElementById('iFrame');
 
	//
	if (formHeight != null)
	{
		iFrame.height = parseInt(formHeight) + 30;
	} 
	else
	{
		iFrame.height = '600px';
	}
}
</script>

 

Add the following to the source page inside of the IFRAME

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
<script type="text/javascript">
if (window.innerHeight &amp;&amp; window.scrollMaxY) {// Firefox
	yWithScroll = window.innerHeight + window.scrollMaxY;
	xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	yWithScroll = document.body.scrollHeight;
	xWithScroll = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	yWithScroll = document.body.offsetHeight;
	xWithScroll = document.body.offsetWidth;
}
document.cookie = "page-height=" + yWithScroll  + "; expires=01/01/2999 10:00:00; path=/;domain=.yourdomain.com";
</script>

Create the IFRAME

1
<iframe id="iFrame" src="http://www.yourdomain.com" width="100%" frameborder="0" scrolling="no" allowtransparency="true" onload="setIFrameHeightToCookie('page-height');"></iframe>

I searched all over and as a last resort I decided to use a cookie to pass the height over. Since we are working across domains trying to use JavaScript to access another frame is out of the question. You will get a security error that there seems to be no way around. 

If you have a better solution please post it in the comments section below and I will update the post. 

Hope this helps! It did for me.

http://www.fitchett.me/wp-content/plugins/sociofluid/images/digg_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/delicious_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/technorati_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/google_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/myspace_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/facebook_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/twitter_32.png

Comments (3)

this line is throwing a syntax error and I tried it anyway to no avail.

readCookie(name) {
var nameEQ = name + "=";

I am getting empty value from cookie.

alert (ca) => Doesn’t give height and all..

Please share your thought on this

Doesn’t seem like this will work on anything except cross sub-domains. You could accomplish the same thing by just setting document.domain of the iframes on subdomains to be the main domain, then browsers will let you communicate between.

You only have access to the cookies on your domain. And the inner iframe is setting a cookie for “yourdomain” while the outer page is trying to access the cookie by the same name for its domain and not finding anything, which is why its coming back as empty for anyone that tries it on 2 different actual domains.

Write a comment

Anti-Spam Protection by WP-SpamFree

Advertise Here