html - Using javascript to write an iframe for a widget - best practices / limitations? -


i'm in middle of development of third-party widget of sorts (an html5/js video player), designed embeddable on third-party sites seamlessly, works in conjunction flash player (the html5/js player in case fallback).

to allow external embedding via single gateway, we're offering embed code looks this:

<script src="http://example.com/embed.php?id=12345678&width=400&height=300"></script>

note .php extension. script perform basic browser agent detection, run bit of backend logic based on 'id' query string, , echo javascript document.write's page actual embed code.

if it's flash-enabled device, document.write code straight <object> flash embed code (no iframe; straight page); if it's ios device, writes <iframe>, src points html document is html5/javascript player -- own .js in <head>, set of <div>s in body make html5/js player, etc.

i'm sure can cleaned / done better. so, questions:

  1. what steps, if any, can or should removed?

  2. is idea begin drop html5/js version iframe, rather write page directly? external .js needed, use in <head>? also, in future, we're need 2-way communication our site (same domain iframe src), iframe offers way allow this, correct?

  3. are there scope issues need worried if loaded within iframe (for instance, our player's version of jquery conflicting what's on third-party parent page)?

  4. is there can/should ensure proper load order don't negatively affect third-party site while our script loads/executes?

  5. is there better/smarter option using document.write write final embed code third-party page (whether it's flash's <object> code or html5/js's <iframe>)? should writing code div include original js line, or safe document.write whatever container happens in?

thanks! javascript's scope issues , asynchronous behaviors have never been strong point of mine...

2,3) if using iframe, separate jquery library has loaded iframe. may enough reason use iframe (prevent version problems). cost of downloading jquery twice unnecessarily in cases.

5) document.write should avoided reasons mentioned unclenorton. however, it'd nice allow user embed without needing call js. approach consider pass in id of element want put player in script tag.

something like: <div id='my-video'></div> <script src="http://example.com/embed.php?id=12345678&width=400&height=300&nodeid=my-video"></script>

then script can hook domready/onload event , build html without document.write using

// should called onload handler document.getelementbyid('<?= $_get['nodeid']?>').innerhtml = myhtmlstring; 

or through boring createelement appendchild calls


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -