Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Can playback be toggled if video is in an iframe?


My original question was in this thread, but has been closed, so I need to ask again.

http://support.jwplayer.com/customer/portal/questions/7511340-can-playback-be-toggled-if-video-is-in-an-iframe-

I have a video that is displayed in an iframe. I know the function onclick='jwplayer().play() can be used to toggle playback of the video, but I cannot get the function to work on my page and I suspect it is because I have the video in an iframe.

Is there any way to get this function to work if the JWPlayer is in an iframe?

-----------------------------

The parent and the iframe pages are not on the same domain, but I do have the ability to add my own Javascript to both pages.

9 Community Answers

Todd

JW Player Support Agent  
0 rated :

You would need to point to the iframe before calling the play() function:

document.getElementById(‘iframe_id_goes_here’).contentWindow.jwplayer().play();

Do the iframe and the page live on the same domain? If not, you will probably run into some cross-domain issues.

Hope this helps,
Todd

tim.marriott

User  
0 rated :

Thank you.

No, the iframe and the page do not live on the same domain.

How would I go about resolving cross-domain issues? Sorry, I'm quite the novice at Javascript.

Todd

JW Player Support Agent  
0 rated :

Do you have access to pages on both domains?

tim.marriott

User  
0 rated :

Yes, I have access to both pages.

Todd

JW Player Support Agent  
0 rated :

Would it be possible to put the iframe on the same domain as the main page? This way you could pause via the contentWindow code above.
Or better yet, just embed our player directly on the main page and control the player directly via our API.

tim.marriott

User  
0 rated :

All of our videos are stored on the one domain and cannot be embedded directly on the page because of the restrictions of the one domain license that we have. That's why we have the need for the iframe.

Is there a way to accomplish what I'm trying to do with Javascript?

Todd

JW Player Support Agent  
0 rated :

This script needs to go into your iframe:

<script> window.onmessage = function() { jwplayer().pause(); }; </script>

And this is the script you need to run when you want to pause from the main page:

document.getElementById(‘iframe_id_goes_here’).contentWindow.postMessage(‘’,’*’);

tim.marriott

User  
0 rated :

I inserted those two scripts into the two pages; however, the scripts did not pause the video when I pressed the button to do so. Is it possible there is a cross-domain issue?

Thanks for your help by the way.

Todd

JW Player Support Agent  
0 rated :

Those scripts were working on my internal cross-domain tests. Please send me a link to your test page so I can investigate further.
You can e-mail it to me at support@jwplayer.com if you do not want to post it in the forums.

This question has received the maximum number of answers.