Page 1 of 1
url of iframe with javascript?
Posted: Tue Jan 07, 2003 2:56 am
by qads
hi,
how would find the url of the page loaded in a iframe with javascript?
here is the code for the iframe i am useing
Code: Select all
<iframe name="redirect" src="redirect.php?id=23" width="25%" hight="50%"></iframe>
i know the src=redirect.php?id=23, that's a redirect, so i need to find the url of the page which is currently showing in the frame.
please help.
thanks alot.
Posted: Tue Jan 07, 2003 6:25 am
by DaZZleD
in another frame/iframe of the same document check to see if the page in the "redirect" iframe has loaded with javascript:
Code: Select all
<script language="javascript">
var intervalID = setInterval('getlocation()',1000); //check every 1000 msecs
function getlocation()
{
if(parent.redirect.document.readyState == 'complete') //check if document in redirect is loaded
{
var frame_location = parent.redirect.document.location.href; //get the document's location
clearInterval(intervalID); //stop the timer
}
}
</script>
Posted: Tue Jan 07, 2003 6:49 am
by qads
page1.htm
Code: Select all
<iframe name="redirect" src="http://localhost/data/redirect.php?ID=23"></frame>
<iframe name="aaa" src="http://localhost/data/page2.htm"></iframe>
page2.htm
Code: Select all
<script language="javascript">
var intervalID = setInterval('getlocation()',1000); //check every 1000 msecs
function getlocation()
{
if(parent.redirect.document.readyState == 'complete') //check if document in redirect is loaded
{
var frame_location = parent.redirect.document.location.href; //get the document's location
clearInterval(intervalID); //stop the timer
}
}
</script>
i dont know anything about js, think you could fix this?
thanks
Posted: Tue Jan 07, 2003 7:21 am
by DaZZleD
you just take the script part and copy it in the body of page2.htm then you will have the location of the redirect frame in variable frame_location of javascript.
Posted: Tue Jan 07, 2003 10:15 am
by qads
that is what i did, and i got this error message (a little help from NS)
їcode]
Error: parent.redirect has no properties
Source File:
http://localhost/data/page2.htm
Line: 7
ї/code]
i have no idea why this is happening
Posted: Wed Jan 08, 2003 2:41 am
by DaZZleD
a reason might be because NS doesn't support readyState property... it's a IE feature only...
you might try to use this (though i'm not sure it will work)
Code: Select all
<script language="javascript">
var timeoutID = setTimeout('getlocation()',5000); //check after 5000 msecs
function getlocation()
{
var frame_location = parent.redirect.document.location.href; //get the document's location
}
</script>
i haven't tested it but give it a shot... hope it helps