Solved

Get URL of a subframe in a frameset

Posted on 2006-10-27
4
458 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link Anchor Not working 9 67
Google map API and Coldfsuion 4 32
How does this modal gets closed? 6 42
Javascript function 3 22
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

752 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