Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change URL of frame2 from frame1 ? 1

Status
Not open for further replies.

may1hem

Programmer
Jul 28, 2002
262
GB
I've created a local web page which uses frames, and I want to be able to change the URL of frame2 from frame1.

Frame1 contains a button which when clicked should change the URL of frame2 to Google's home page. Frame1 also contains a textbox which I was using to check if the OnClick event was triggering ok, and it is, but Frame2 doesn't change to Google. Can anyone help me to get this working?

Here's the code for the parent document:
----------------------------
<html>
<head>
<script type="text/javascript">
function populateFrames()
{
frame1.location = "frame1.html";
}
</script>
</head>
<frameset cols="*,*" name="fraSet" id="fraSet" onload="populateFrames()">
<frame name="frame1" id="frame1">
<frame name="frame2" id="frame2">
</frameset>
</html>
----------------------------

Here's the code for frame1:
----------------------------
<html>
<head>
</head>
<body>
<form>
<input type="button" onclick="parent.document.getElementById('frame2').location = ' txt1.value='Hello';" value="Load URL">
<input type="textbox" id="txt1" name="txt1">
</form>
</body>
</html>
----------------------------
 
Try:
Code:
<input type="button" onclick="parent.[red]frames[/red].[blue]frame2[/blue].location = '[URL unfurl="true"]http://www.google.co.uk'...[/URL]



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks Phil, it works fine now!

But why doesn't parent.document.getElementById('frame2').location work? I have something similar working elsewhere in my code.. =/
 
The getElementById method does not provide access to the location property of the frame. In fact using the getElementById method returns a different set of available properties for the frame object.

You can try this code out to check what properties are available for a given object.

Code:
function My_Object_Properties(myobject);
var props="";
for (var name in myobject) {
props+=name + "<br>";  
}
document.write(props);
return true;
}

My_Object_Properties(parent.frames.frame2);
yields a decidedly different set of properties than

My_Object_Properties(parent.document.getElementById('frames2'));
There is no location property available this way.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top