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

Posted on 2003-03-21
Medium Priority
Last Modified: 2010-04-09

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)

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

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

Please help...
Question by:Marqis
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
  • 3

Expert Comment

ID: 8184869


Author Comment

ID: 8185496

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.
LVL 53

Expert Comment

ID: 8186375

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.

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.


Author Comment

ID: 8186757

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

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?
LVL 53

Accepted Solution

COBOLdinosaur earned 150 total points
ID: 8186880
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.


Author Comment

ID: 8188206
Could you give me a quick code example of both methods?
LVL 53

Expert Comment

ID: 8188313
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.


Featured Post

Technology Partners: 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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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…
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…
Suggested Courses

777 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