javascripthtmlembeddinggoogle-gadget

How to create embeddable gadget with Javascript and PHP?


I'm programming in Javascript and PHP. I've created a simple website that allows to fill in a quizz and get result. Now I would like to give users opportunity to embed this quizz on their website. How to do this? It should work in some near manner like Google Gadgets, Adsense and that: that so when someone will put my html code (with JS?) on their websites, quizz will display and work on their site.

Do you know any tutorials about doing such things or tips for me how to start searching and learning about it?


Solution

  • The easiest way, which is also best performance- and security-wise, is to use <iframe>. Just create small version of your page for embedding.

    <script> is loaded synchronously and gets access to site's cookies, so it's not a good solution for embedding.

    If you just ask your users to embed <script> in place where they want the gadget to be, you'll be able to generate markup with document.write (easy, works in HTML only).

    A better way is to ask users to invoke function from your script that inserts code into selected DOM node (using W3C DOM). This allows smarter webmasters to load script asynchronously. SWFObject is designed like that.