fkrust
fkrust

Reputation: 133

Controlling play/pause actions of javascript mp3 player within a frame from other iframe

I had an webradio project for a client, so I need to put in a mainpage (index.html) one iframe with the audio stream and another iframe with the Wordpress webradio page to guarantee the audio won't reload with the page navigation between the site.

The problem is: the "stop button" its on the webradio page iframe, so even if I target the "a" for the audio stream iframe, it doesn't work. I read some of topics here and tried "parent.document" too but nothing works. Can someone give me some light?

The page in question: http://radiotalent.com.br/

Upvotes: 0

Views: 536

Answers (3)

Mike
Mike

Reputation: 894

think of it this way. If you have two iframes, your connection is the parent page.

What you'd want to do, lets assume you're using regular javascript at first (consider JQUERY THOUGH)

Say you have iframe 1, with an ID of "iframe1" and the second "iframe2"

to access iframe2 from iframe1

var iframe2 = parent.document.getElementById("iframe2");

or the other way around

var iframe1 = parent.document.getElementById("iframe1");

EDIT:

X-FRAME-OPTIONS STRIKES AGAIN, seems the poster was trying to have cross-domain access when this is specifically denied by iframes when the sites use this particular protection.

Upvotes: 0

OnoSendai
OnoSendai

Reputation: 3970

Let's assume you have two IFrames inside a root document, following this disposition:

  • Root document
    • IFrame1
    • IFrame2

If you want to call, say, a method located in IFrame2 from IFrame1, then parent is indeed your friend. The code in IFrame1 would look something like this:

parent.document.getElementById("IFrame2").contentWindow.Method();

The following marker code indicate the position of each member on the above line:

^ [parent (Root)]
       ^ [parent document]
                ^ [The target frame]
                                          ^ [The window object in the frame]
                                                        ^ [The JS method itself]

Now, keep in mind that you won't be able to use this if the IFrames reference content in different domains because of the "Same Origin" security policy.

Upvotes: 1

Thrash Bean
Thrash Bean

Reputation: 658

From the webradio frame call iframe1.stop() function. That might help.

Upvotes: 0

Related Questions