Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get URL of a subframe in a frameset

Posted on 2006-10-27
4
Medium Priority
?
475 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to dynamically set the form action using jQuery.

671 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