Link to home
Start Free TrialLog in
Avatar of abaIT4000
abaIT4000

asked on

Get URL of a subframe in a frameset

JavaScript newbie

Trying to write script to do an alert in FirstFrame.html which will display the URL of ThirdFrame.html.  Have tried several different methods but can't make it work.  Want to use .window.loacation.href.  Can you help me understand how to do it with a function in the head and an onclick= in the body using
<a href="#" onClick="???????">Get Third Frame's Info</a>
Here is code of index.html

<html>
<head>
      <title>Untitled</title>
</head>
<frameset rows="*,*" framerborder="4">
      <frame src="FirstFrame.html" name="firstFrame">
            <frameset cols="*,*">
              <frame src="SecondFrame.html" name="secondFrame">
              <frame src="ThirdFrame.html" name="thirdFrame">
            </frameset>
</frameset>
</html>
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

abaIT4000,

In the head make the function below ...

function getURL() {
  alert(parent.thirdFrame.href);
}

In the anchor tag put an onclick event to call the function.  Something like this ...

<a href="#" onclick="getURL(); return false;">Get Third Fram Info</a>

Let me know how this works.  Let me know if you have any questions or need more information.

b0lsc0tt
Avatar of abaIT4000
abaIT4000

ASKER

b0lscott ... thanks but keep getting error "undefined."  Maybe would help if I included code for the three frames of the frameset.

Index.html
<html>
<head>
     <title>Untitled</title>
</head>
<frameset rows="*,*" framerborder="4">
     <frame src="FirstFrame.html" name="firstFrame">
          <frameset cols="*,*">
             <frame src="SecondFrame.html" name="secondFrame">
             <frame src="ThirdFrame.html" name="thirdFrame">
          </frameset>
</frameset>
</html>

FirstFrame.html  
<head>
      <title>First Frame</title>
      <script type="text/javascript">
            function getURL()
                {
                    alert(parent.thirdFrame.href);
                }
      </script>
</head>
<body>
<div align="center">
<h2>First Frame</h2>
</div>
<h3><a href="#" onclick="getURL(); return false;">Get Third Frame's Info</a></h3>
<h3><a href="#" onClick="???'); return false;">Get Main Frame's Info</a></h3>
</body>
</html>

SecondFrame.html  
<head>
      <title>Second Frame</title>
 </head>
<body>
<div align="center">
<h2>Second Frame</h2>
</div>
</body>
</html>

ThirdFrame.html  
<head>
      <title>Third Frame</title>
 </head>
<body>
<div align="center">
<h2>Third Frame</h2>
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm glad that I could help you.  Thank you for the grade, the points and the fun question.