Click to See Complete Forum and Search --> : Referencing an iframe (asp page) through a .js file?


rizshe
02-02-2006, 06:29 AM
Hi,
Here is the .js file function in which i need to implement this:



function my_DropFunc() // Modified by Rizwan
{
var dropTarget = dd.obj.getEltBelow();
if (dropTarget == null || dropTarget == "undefined")
{
MydtObj = "none";
Glbtemp.moveTo(Glbtemp.defx, Glbtemp.defy);

}

else

{
MydtObj = dropTarget.name;

if (MydtObj == "background")
{
var temp= dd.obj.name
dd.elements.background.swapImage(temp+'.jpg');
dd.obj.hide();
}
else
{
Glbtemp.moveTo(Glbtemp.defx, Glbtemp.defy);
}
}
}


Instead of background.swapImage I want to change the iframe which is present in .asp file and change its background depending on the drop object i'm getting in .js file
Bear in mind that I already reference .js in asp file.

Thanks

Kor
02-02-2006, 07:01 AM
Are there the two pages belong to the same domain? Otherwise it is not possible with javascript.

rizshe
02-02-2006, 07:05 AM
They belong to the same domain.

Kor
02-02-2006, 09:24 AM
The window object loaded in an iframe is to be found as:

document.getElementById('iframeid').contentWindow

some function resident on an iframe is to be triggered as

document.getElementById('iframeid').contentWindow.myFunction()

make sure the iframe has an id.

rizshe
02-02-2006, 09:41 AM
can you please elaborate this a bit more as I'm not good in javascript.

Thanks

Kor
02-02-2006, 10:04 AM
Referencing an iframe (asp page) through a .js file?

To refere an iframe (in fact a page loaded in an iframe), the statment is something like this example:

var myWindowInIframe = document.getElementById('iframeid').contentWindow

this is your window object you are looking for. now you can find an element on this page as:

myWindowInIframe.document.getElementById('myelementid')

or u may call a function resident in iframe loaded window as:

myWindowInIframe.thatFunction()

Kor
02-02-2006, 10:07 AM
Of course, your asp page (or php or whichever dynamic might be) should be build (by asp or php or whichever dynamic might be) as a valid HTML page

rizshe
02-02-2006, 10:43 AM
I'll try it tomorrow as i'm off for the day.