Question

I am making a media player type application which other site developers can embed on their website. I need to provide them with a set of javascript functions which they can call from other parts of their website. I have a swf file in it with external interface hence I require it to be loaded in iframe.

How can I make the javascript inside my iframe to be accessible from outside?

I saw x-frame-options but it's allow-from directive does not work with chrome and safari. What are my options?

Was it helpful?

Solution

The HTML5 way to do it is postMessage.

If you cannot rely on its being used in an HTML5 environment, (a) that's really sad, and (b) you can use Porthole.

OTHER TIPS

it seems like you want to provide embeded code for your video player like youtube there is two option for that you can provide directly I-frame code to other website developers so they have to just paste the code in their page for E.g

<iframe width="560" height="315" src="//website.com/videoid={videoid}" frameborder="0" ></iframe>

in Iframe Page target you can create your login and put your video code, html and javascript..

another option

if you want to go with javascript you they have to include your javascript into their page and in your javascript you have to implement login to create a I-frame using javascript and give iframe src dynamically ..

In that case you can definitely access your I-frame content using javascript beacause your javascript and I-frame belongs to same domain you can read more abour same orign policy Same Origin

EDIT: HERE IS SOME EXMPLE CODE HOW TO CREATE I-FRAME USING JAVASCRIPT

<script type='text/javascript' charset='utf-8'>     
   var iframe = document.createElement('iframe');       
   document.body.appendChild(iframe);

   iframe.src = 'URL OF CONTENT YOU WANT TO PROVIDE';       
   iframe.width = 'THE WIDTH YOU WANT';
   iframe.height = 'THE HEIGHT YOU WANT';
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top