views:

41

answers:

4

Hi all,

I recently created a website for a friend (asp.net/sql server), the website includes news of his company and he and his team update this frequently.

The question has been asked if i could now create a widget / api of some sort that visitors of the website could now include the news on there own website should they wish too. I feel this needs to be a one line of code intergration or something that is extremely easy to intergrate.

Any recommendations or articles are welcome.

EDIT: how is something like this created

http://img830.imageshack.us/img830/7769/codingabandwebsitecreat.png

Thanks

A: 

Check out WidgetBox. You can create your own widget or download pre-built ones.

Alex
i would really like to roll my own..
Gary
A: 

With jQuery's ajax and an asp.net handler that returns an injectable html chunk is my off hand guess at simple way. Other's will probably know of frameworks if you don't want to roll your own. Is RSS to primitive?

Gabriel
A: 

you could also write a REST service in WCF since you're using asp.net and have it return XML or JSON, depending on how you write your widget.

Andrew Church
A: 

How something like that is created... Well, I've created a number of these and the process is fairly simple. Sorry I don't have an article to reference. Create a 'widget creation/builder' page with input parameters, when submitted either store those in the database and return an ID to associate with those settings, or generate a list of param's for those settings, or both. Simply output the <script> tag into a textbox. Like so (inside an AJAX callback):

$("#results").html("&lt;script type='text/javascript' src='" + widget_path + params + "'&gt;&lt;/script&gt;");

Where widget_path is the absolute path to the widget ASP script, and params is either something like key=454 or theme=sunny&source=34&count=50 etc. Either manually or using something like jQuery.param to serialize the form. An alternative would be two <script> tags with settings in the 2nd and calling a widget initialize function.

They can copy and paste that into their site, and that ASP script should output only JavaScript, which you can either document.write() or use a JS library (such as jQuery) to operate on the DOM (.click() etc). If using a database the ASP script would check the key param and grab the widget settings, if not then simply process the params. It's important to mention if you want to communicate back and forth with an API, you need cross-domain enabled or you could simply use JSON (in ASP script check for a 'callback' parameter, wrap JSON in that function name, and use jQuery.getJSON with &callback=? at the end); there are other methods of course.

If you use a database, make sure to take security into account (SQL injection, etc.)

WidgetBox looks like a good, mainline method as well.

Eric Muyser