0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That looks like a solution. I don't want to rely on HTML5 as already my application fails on mobile without flash. Can you tell how porthole works for browsers without support of postMessage?
Here is a detailed explanation.
1

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>

4 Comments

I have gone the second way. However, browser does not allow script access to iframe from other domain. eg. window.frames[0].targetfunction() gives security error in console. My scripts inside iframe are not accessible from the parent window
if your script and Iframe domain is same then you can access iframe too.. answer edited
That's what I assumed at first, but it didn't work out. Script's domain is taken to be the domain that embeds script not the origin of script. Hence, if abc.com embeds src="xyz.com/script.js" , the domain for scripts.js shall be abc.com and it won't have access to iframe from xyz.com .
hmm here you make mistake you not neeed to provide javascript code to another website users .. you have to give your javascript source link for E.G if your server of video is www.abc.com then <script src='abc.com/js.js' and iframe is <iframe src='abc.com\videoid="2" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.