views:

147

answers:

1

I wanted to give my users a little piece of JavaScript or HTML code that they could put on their site and show information about them. Kind of like StackOverFlows new feature Flair.

I have an idea of how to code it. I was going to give them some JS with a HTML that had a DIV id="MySite_Info". Then the JS would go to my site and pull some JSON or XML and then fill in the data with a DIV in the HTML I gave them on their site.

Is there a better way to do this? Or any examples online I should follow? Whats the best way to create these javascript snippets? (Not sure what the proper name is)

+1  A: 

There are two basic options.

  1. Images (and pictures of text suck)
  2. JavaScript - as you described

The approach I would take would be to:

  1. Dynamically generate the JS using a server side process. This would include data for the user (using a JSON generator to easily produce the data in a suitable format).
  2. Build the badge using standard DOM methods
  3. Find the element with the document id and appendChild the generated badge
David Dorward
Building the badge using DOM methods is 10x to 50x slower than using innerHTML with raw HTML. I would recommend just piping back HTML from a web service into a div.
Jesse Dearing
I think I will just send back HTML and use innerHTML. Thanks for the help guys.
Bernie Perez