/    Sign up×
Community /Pin to ProfileBookmark

Calling a function in an iframe

I have an upload script that loads into an iframe(‘upload’) within an iframe(‘content’);

It passes a user entered value to a function uploaded() in ‘content’ as follows;

top.content.uploaded(value);

This works just fine in all major browsers.

However, I needed to assign the iframe called ‘content’ a dynamically generated name, so it might now be called, say, ‘content12345’. I store the ‘12345’ value in a hidden input field in the top document so that it can be referenced from any iframe.

I thought this should work…

csx = top.document.getElementById(‘csx’).value;
contentid = “top.content” + csx;
contentid.uploaded(value);

…but it genereates an error “top.contentid is undefined”. Note that it collects the value of csx correctly.

How do I dynamically name the iframe reference within the javascript and call a function within that iframe?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@chestertbauthorDec 19.2008 — Sorry All,

I kept looking for the solution to this after I posted this, and found a post right here at xx that pointed me in the right direction.

The solution is as follows;

csx = top.document.getElementById('csx').value; //gets the content id from the top window

contentid = "content" + csx;

top.document.getElementById(contentid).contentWindow.uploaded(pictarget);

Cheers

CTB
×

Success!

Help @chestertb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...