.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Friday, February 03, 2006

Content Syndication using Dynamic Javascript

In the
previous post
we saw how to use RSS to syndicate your web content. If you want to syndicate your
content for other web sites, this method demand work from the consumer work site in terms of reading
the feed and interpreting it. An alternate method, is content syndication using dynamic javascript.

This example show you how,
The site that consumes your content will include a block of script like this where ever they want your
content to be shown,


<SCRIPT SRC="http://www.directkerala.com/syn/js.aspx?js=y"> </SCRIPT>


When the webpage is rendered it calls this page in your web site to render the content. In your
web site ( In our example, js.aspx ), you will add code similar to this,



private void Page_Load(object sender, System.EventArgs e)
{
if (Request["js"] == "y")
{
Response.ContentType = "application/vnd.javascript";
Response.Write ("document.write('");
Response.Write ("<a href=http://www.directkerala.com><img border=0 src=http://www.directkerala.com/images/dklogohome.jpg>");
Response.Write ("</a>')");
Response.End();
}
}



Please take a note of the MIME[Content] type here, it is set as "application/vnd.javascript". This will enable dynamic
javascript and your "document.write" will write the html you have embedded within. This is a very effective way of providing
content and attracting users to your site.

0 comments: