An embeddable JSONP javascript widget template

Recently Iโ€™ve been hacking together a little online poll creator - pollfu. For the app I needed to have the option to embed the poll on an external website. One of the best examples of this is the checkout widget by stripe. The cool thing about the stripe widget is it loads everything it needs through that one script.

This is the core of what I came up with:

This is what it can do:

After you have jquery and your scripts loaded in you can use it grab data from your server using jsonp (there is a super simple example commented out in the source).

Another cool thing to try is setting widget variables on the script tag using data attirbutes (eg data-id=โ€1โ€). Once you have a reference to the script tag these are super easy to read in eg:

<script src="" data-id="9"></script>

This is an example of the end result embedded poll for pollfu:

๐Ÿ‘‹ Are you an ๐Ÿ‡ฆ๐Ÿ‡บ Australian developer or IT professional? Go check out my site Australian Technology Jobs - a Premium developer and IT job board and find awesome Australian dev jobs (and people).
Questions or comments? Follow me on twitter!
Follow @lukencode