Powered By Blogger

Search

Wednesday, September 10, 2008

Cross Domain Iframe Resize

Cross Domain iframe Resize


Domain A: Html Page
There we want add one dummy Html Page with JavaScript

Dummy_Page.html
<html>
<head>
</head>
<body>
</body>
</html>
<script language="javascript" type="text/javascript">

var hashValue = window.location.hash
if ((hashValue != null) (hashValue.length != 0))
{
var pairs = hashValue.split('&');
if ((pairs != null) && (pairs.length > 0))
{
window.top.document.getElementById((pairs[1].split('='))[1]).style.height =(pairs[0].split('='))[1] +"px";
}
}
</script>

Domain A: Iframe Page

<html>
<head>
</head>
<body>
<table class="content" align="center" width="845">
<tbody>
<tr>
<td align="center" valign="top">

<iframe id="Home" scrolling="auto" frameborder="0" name="HOME" style="width: 100%;" src="http://www.DomainB.com/Home.aspx" >
</iframe>
</td>
</tr>
</tbody>
</table>

<script language="javascript" type="text/javascript">
var iframe= document.getElementById("Home");
iframe.src=iframe.src +"#frameID="+ iframe.id +"&site=http://www.DomainA.com/Dummy_Page.html";
</script>
</body>
</html>

Domain B: Frameheight.js
This script file want to include in Domain B Pages

function call()
{
var hashValue = window.location.hash.substring(1);
if ((hashValue == null) (hashValue.length == 0))
{ }
else
{
var pairs = hashValue.split('&');
if ((pairs != null) && (pairs.length > 0))
{
var iframeID = (pairs[0].split('='))[1];
var parlocation = (pairs[1].split('='))[1];
manage(iframeID,parlocation)
return;
}
}
setTimeout("call()",10);
}
function manage(iframeID,parlocation)
{
set_cookie("iframeID",iframeID);
set_cookie("location",parlocation);
document.getElementById("Home_sub").src=parlocation + "#Height=" + (document.body.offsetHeight+30) + "&iframeID=" + iframeID;
}

if( get_cookie("iframeID") != null && get_cookie("location") != null)
{
document.getElementById("Home_sub").src= get_cookie("location")+ "#Height=" + (document.body.offsetHeight+30) + "&iframeID=" + get_cookie("iframeID");
}
else
{
call();
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
var cookie_string = name + "=" + escape ( value );

if ( exp_y )
{
var expires = new Date ( exp_y, exp_m, exp_d );
cookie_string += "; expires=" + expires.toGMTString();
}

if ( path )
cookie_string += "; path=" + escape ( path );

if ( domain )
cookie_string += "; domain=" + escape ( domain );

if ( secure )
cookie_string += "; secure";

document.cookie = cookie_string;
}
function get_cookie ( cookie_name )
{
var results = document.cookie.match ( '(^;) ?' + cookie_name + '=([^;]*)(;$)' );

if ( results )
return ( unescape ( results[2] ) );
else
return null;
}




Domain B: All Pages(HTML , ASPX ,etc....)

(Red color Marked Code want to insert in all the pages)

<html>
<head>
</head>
<body>
<table class="content" align="center" width="845">
<tbody>
<tr>
<td align="center" valign="top"&gt
;<div style="padding:4px;border:solid 1px #cccccc;width:300px">
</div>
<div style="padding:4px;border:solid 1px #cccccc;width:300px">
</div>
</td>
</tr>
</tbody>
</table>
</form>

<iframe id="Home_sub" frameborder="0" name="home_sub" style="height:1px;width:1px;" src="">
</iframe>

<script src="Js/FrameHeight.js" type="text/javascript"></script>

</body>
</html>







No comments: