Solved

Get URL of a subframe in a frameset

Posted on 2006-10-27
4
437 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I'm glad that I could help you.  Thank you for the grade, the points and the fun question.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now