Posted by: prajapatinilesh | October 24, 2007

Frame Example With JS

//to get main div obj inside frame within frame

1) one mainfile.php

<div id=’master’ name=”master”>
<iframe id=”Iframe1″ name=”Iframe1″ src=”p1.php” width=”96%” height=”800″></iframe>
</div>

2) this one is p1.php file

<?
echo “p1.php”;
?>
<iframe id=”Iframe2″ name=”Iframe2″ src=”p2.php” width=”96%” height=”500″></iframe>

 

3)

this one is p2.php file

<?
echo “p2.php”;
?>
<script language=”javascript”>
//alert(‘p2.php’);
/*if (window.frames[“Iframe2”] && window.frames[“Iframe2”] != ‘undefined’) {
alert(‘hi’);
}*/

//or

//alert(window.parent.window.parent.document.getElementById(“master”));

if (window.frames && window.frames != ‘undefined’) {
currentFrameObj = window.frames;
parentFrameObj = window.frames.parent;
if (parentFrameObj && parentFrameObj != ‘undefined’) {
//alert(parentFrameObj.name);
mainWindowObj = parentFrameObj.parent;
if (mainWindowObj && mainWindowObj != ‘undefined’) {
mainDivObj = mainWindowObj.document.getElementById(‘master’);
alert(mainDivObj);
alert(mainDivObj.id);
}
}
}
</script>

 

***********************************************************************

//get div object  on main window which is available inside the frame

1) pmain.php

<input type=”button” value=’Click here’ onclick=”callObj();”>
<div id=’master’ name=”master”>
<iframe id=”Iframe1″ name=”Iframe1″ src=”p1.php” width=”96%” height=”800″></iframe>
</div>
<script language=”javascript”>
alert(‘main file called. Prajapati Nilesh….’);
function callObj() {
alert(‘call obj function called’);
if (window.frames[“Iframe1”] && window.frames[“Iframe1”] != ‘undefined’) {
divObjInsideFrame = window.frames[“Iframe1”].document.getElementById(‘divFrame1’);
alert(divObjInsideFrame);
alert(divObjInsideFrame.id);
}
}
</script>

2) p1.php

<?
echo “p1.php”;
?>
<div id=’divFrame1′ name=’divFrame1′></div>
<iframe id=”Iframe2″ name=”Iframe2″ src=”p2.php” width=”96%” height=”500″></iframe>

*******************************************************************************

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: