Forum Moderators: open

Message Too Old, No Replies

Checking a frames src

using a frame src in an If Else statement

         

Tamarick

2:48 am on Feb 18, 2004 (gmt 0)

10+ Year Member



I want to return values based on the one of the parent's child frame src.

Here's a real basic example of what I'm trying to do:

<script type="text/javascript">
if (parent.frames.mainframe.src = 'FOO.html')
{
document.write('It is foo!');
}
else
{
document.write('Not foo Yo!');

}
</script>

It always returns the top statement. No matter what the actual src is.

Purple Martin

4:28 am on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The frame source is originally set to 'FOO.html'. Even if the content document of that frame is changed later on, the top-level frameset document doesn't know about it and so the src property still returns the same value.

You can reference the current URL of the child frame by going right down to the child's document object, like this:

parent.frames.mainframe.document.location.href

(fingers crossed that I got the referencing right!)

RonPK

1:10 pm on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tamarick, in your current if-statement you're using a single =. That makes it an assignment operator. What you need here is the comparison operator: ==