How does social plugin work?
Introduction
I am planning to create a widget much like, Facebook provides for likes, share etc. Basically the requirement is:
- The client will include JavaScript provided by us.
- The client can, now, put our widgets in the page having the JS. The widget placeholder looks like
<nw:fav id="911"/>
. - When page gets loaded, the JavaScript replaces the placeholders with actual HTML. The JavaScript also keeps t开发者_C百科his DIV updated with dynamic (perhaps using long polling) content.
Problem
I am not sure how to do step #2.
- How JavaScript will get all the
<nw:...
tags and all the attributes of it? - How to replace the tag with real HTML tag?
Constraints
- I am trying to avoid JQuery or any other JS library, since we may cause conflict if the client is also using JQuery, may be some other version.
- I don't really want to use IFrame.
I am looking for approaches. Open for suggestions.
The facebook connect JS SDK is open source. You might find the xfbml.js file useful. See this link.
Basically when the document loads, the code walks the dom looking for elements that have a specific namespace (FB uses fb, you appear to want to use nw). Find those elements and then replace them with whatever content you need.
精彩评论