Knowing which iframe called

A

Andrew Poulos

I have a page with one or more IFRAMEs on it. When the user clicks an
element in the page, that's in the IFRAME, it triggers a function in the
parent page.

How can I tell which IFRAME's content triggered the function without
putting page specific parameters? For example, I've tried

window.parent.fHighlight(window);

in the IFRAME and this in the parent page

fHighlight = function(doc) {
var allIFm= document.getElementsByTagName("iframe");
for (var i = 0; i<allIFm.length; i++) {
alert(allIFm == con);
}
};

but it never alerts as TRUE.

Andrew Poulos
 
A

Andrew Poulos

Randy said:
Andrew Poulos said the following on 12/4/2007 11:55 PM:
I have a page with one or more IFRAMEs on it. When the user clicks an
element in the page, that's in the IFRAME, it triggers a function in
the parent page.

How can I tell which IFRAME's content triggered the function without
putting page specific parameters? For example, I've tried

window.parent.fHighlight(window);

in the IFRAME and this in the parent page

fHighlight = function(doc) {
var allIFm= document.getElementsByTagName("iframe");
for (var i = 0; i<allIFm.length; i++) {
alert(allIFm == con);


Where is "con" defined and what is it supposed to be testing against?
Hard to tell you why you don't get TRUE if nobody knows what you are
testing against. Or, is the test supposed to be against "doc"?

My bad, 'con' should be 'doc' in the example above. At any rate it
doesn't give TRUE.

Andrew Poulos
 
A

Andrew Poulos

Randy said:
Andrew Poulos said the following on 12/5/2007 3:15 PM:
Randy said:
Andrew Poulos said the following on 12/4/2007 11:55 PM:
I have a page with one or more IFRAMEs on it. When the user clicks
an element in the page, that's in the IFRAME, it triggers a function
in the parent page.

How can I tell which IFRAME's content triggered the function without
putting page specific parameters? For example, I've tried

window.parent.fHighlight(window);

in the IFRAME and this in the parent page

fHighlight = function(doc) {
var allIFm= document.getElementsByTagName("iframe");
for (var i = 0; i<allIFm.length; i++) {
alert(allIFm == con);

Where is "con" defined and what is it supposed to be testing against?
Hard to tell you why you don't get TRUE if nobody knows what you are
testing against. Or, is the test supposed to be against "doc"?

My bad, 'con' should be 'doc' in the example above. At any rate it
doesn't give TRUE.


Not even sure why I had to ask though. You are going to run into the
same issue that is in a semi-ongoing thread about how to know what
called a function. Without you explicitly telling it which document it
is coming from, you won't know for sure.


Assuming that the source page for an IFRAME is unique, within the page
(ie no two IFRAMEs have the same SRC value) can the IFRAME's source page
know what IFRAME its in?

BTW this won't be cross-domain.

Andrew Poulos
 
P

pr

Andrew said:
Randy said:
Andrew Poulos said the following on 12/5/2007 3:15 PM:
Randy Webb wrote:
Andrew Poulos said the following on 12/4/2007 11:55 PM:
I have a page with one or more IFRAMEs on it. When the user clicks
an element in the page, that's in the IFRAME, it triggers a
function in the parent page.

How can I tell which IFRAME's content triggered the function
without putting page specific parameters? For example, I've tried

window.parent.fHighlight(window);

in the IFRAME and this in the parent page

fHighlight = function(doc) {
var allIFm= document.getElementsByTagName("iframe");
for (var i = 0; i<allIFm.length; i++) {
alert(allIFm == con);

Where is "con" defined and what is it supposed to be testing
against?
[...]

Assuming that the source page for an IFRAME is unique, within the page
(ie no two IFRAMEs have the same SRC value) can the IFRAME's source page
know what IFRAME its in?

BTW this won't be cross-domain.


With a small modification, your original code should be sufficient:

var fHighlight = function(w) {
var allIFm= document.getElementsByTagName("iframe");
for (var i = 0; i<allIFm.length; i++) {
alert(allIFm == w.frameElement);
}
};

A window's frameElement property identifies the iframe element that
hosts it (if not cross-domain or using a file:// url in IE).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top