Solved

Get URL of a subframe in a frameset

Posted on 2006-10-27
4
444 Views
Last Modified: 2013-11-19
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>
0
Comment
Question by:abaIT4000
  • 3
4 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17822526
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
0
 

Author Comment

by:abaIT4000
ID: 17824712
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>
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 300 total points
ID: 17827369
Sorry for the mistake.  I didn't look at the Javascript you had in the first comment close enough.  The function getURL should have the alert line below instead.  You were missing location.

   alert(parent.thirdFrame.location.href);

Let me know if you still have a problem or if you have a question.

bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17827473
I'm glad that I could help you.  Thank you for the grade, the points and the fun question.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question