I have a number of iframes calling a function in my main page. Is there a way to find out the ID of the iframe which called the function?
There are all part of same domain so that should not be an issue.
Thank you for your time.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most common way is to have the control pass itself to the function
Another way would be by using the:
As documented here.
A third way but not as reliable would be by using:
The latter is not the best approach.
In my personal opinion I’d go with the first one, as it will work 100% of the time, and won’t give you browser issues.
UPDATE
To get the current iframe’s id (assuming you don’t have nested iframes on the same page), you can simply use:
And then simply pass it along with the call to your function. just make sure the body has the same ID as your iframe for example.
Let me know if it helps you.