Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

Can you get information on an iframe before it's defined?


Let me explain, I'm making a tabbed site with the content in an iframe. I want the current tab (content of the iframe) to be a different colour. Since the tabs are at the top how can I know what page I'm on?

If I put an alert before <iframe> it's null or undefined or doesn't even pop up depending on the method of tracking down the iframe. If I put the alert after the <iframe> it's populated.

My code:

<script language="JavaScript">
var items = new Array();
items['a'] = '/a.php';
items['b'] = '/b.php';
items['c'] = '/c.php';

for(var item in items)
{
alert(document.getElementById("icontent"));

if(document.getElementById("icontent").name == items[item])
{
document.write("<td class='tab_current'>"+item+"</td>");
}
else
{
document.write("<td class='tab'>"+item+"</td>");
}
                   
</script>

<iframe name="icontent" id="icontent" src="/main.php" height="300" width="100%" border=0></iframe>

Please help...
0
Marqis
Asked:
Marqis
  • 3
  • 3
1 Solution
 
heronganCommented:
alert(document.frames['icontent'].location);


Hero
0
 
MarqisAuthor Commented:

document.frames['icontent'] is only defined/populated after the iframe tags. I need to know what page is in the iframe before it's defined. Or on the 2nd pass or whatever.
0
 
COBOLdinosaurCommented:
alert(document.getElementById('icontent').src);

This:>>>I need to know what page is in the iframe before it's defined.

Is not logical.  If something is undefined, then obviously it cannot have any properties because it does not exist.  If it is loaded, it is defined. Otherwise the browser could not render it.

Cd&
0
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!

 
MarqisAuthor Commented:

>I need to know what page is in the iframe before it's
>defined.

I know that it doesn't sound particularily logical, but html is interpreted and it sometimes takes several passes over the code to render a page. How can I use those two features to do what I want?

Surely somebody else out there has tabbed iframes like what I'm doing?
0
 
COBOLdinosaurCommented:
You can't get the value of soemthing before it is there.  It does not matter how many passes it makes.  It has not properties until it is there.  Even if there was some event that you could fire during rendering (which there isn't) you could not get any value before it is rendered.

Yes others have tabbed Iframes.  They either set the after the load is completed, or they pick it up off of the events that initiate the load.  Either way is dead simple.  You are looking for a complex way of solving a simple problem;  and you are not going to get what you want without a custom browser.

Cd&
0
 
MarqisAuthor Commented:
Could you give me a quick code example of both methods?
0
 
COBOLdinosaurCommented:
You give me a B on a low point question and then want code examples?

on the link to load the new source you do it this way:

<a href="blah.htm" target="icontent"
   onclick="document.write('td etc..')">go to blah</a>

The other way requires a variable on the target page and for the on click you set a test for it.

Cd&
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now