I am in the beginning stages of designing a widget and a design question came up for what is more advantageous - to have it as an IFrame or to use another technology.
Has anyone built widgets before to be embedded into other sites? What is the best was to design/architect them? Any particular good practices?
Thanks, Alex
The difference between the iframe and widget embed options is that the widget can take on CSS properties of the page it is embedded on, and the iframe will not.
Google recommends refraining from creating iframes. At there Webmasters Help Forum, Google clearly stated that iframes may cause problems for them: IFrames are sometimes used to display content on web pages. Content displayed via iFrames may not be indexed and available to appear in Google's search results.
iFrames are an HTML tag and have been around for absolutely ages having been introduced back in 1997. Despite their age, they are still commonly used and are supported by all modern browsers.
IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.
In general, if you are going to be using dynamic data from your server you should use an iframe, if not you shouldn't.
Advantages of iframes:
Advantages of JS only widget
If you're still having trouble deciding you should look at how other similar widgets are built and also consider the implications of same origin principle.
I have embedded several widgets into my personal website. I will briefly go through a few examples:
Facebook comments
// Facebook comments
<fb:comments xid="12345678" numposts="3" width="380"></fb:comments>
// Facebook initialization
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '123456789123456789', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
// Twitter tweets
<div id="tweets-container"></div>
<script>
new TWTR.Widget({
profile: true,
id: 'tweets-container',
loop: false,
width: 250,
height: 200,
theme: {
shell: {
background: 'transparent',
color: '#3082af'
},
tweets: {
background: 'transparent',
color: '#444444',
links: '#1985b5'
}
}
}).render().setProfile('TwitterUsername').start();
</script>
Google Chatback badge
// Google Chatback badge
<iframe src="http://www.google.com/talk/service/badge/Show?tk=z01q6amlq6ob76db19rdnikg1pbce3ff3ln9076tc8unrn37r3gmje9pf3gvl80num7ta10tv34ou7has2u2th5btn3uoouvpcufnqolc1mj77nmgld5mm3qf3reqkd3jqcvemqlpr8b04pf0qaf7osm10lo6kioji176dpcn&w=200&h=60" allowtransparency="true" width="200" frameborder="0" height="60"></iframe>
Google Calendar
// Google calendar widget
<iframe src="http://www.google.com/calendar/embed?showTitle=0&showCalendars=0&showTz=0&mode=WEEK&wkst=2&hl=en&src=nicohome%40gmail.com&color=%232952A3&ctz=Europe%2FHelsinki" style=" border-width:0 " width="557" height="445" frameborder="0" scrolling="no"></iframe>
Delicious Bookmarks
// Delicious bookmarks
<script type="text/javascript" src="http://feeds.delicious.com/v2/js/Nicodemuz?title=My%20latest%20bookmarks&icon=s&count=10&bullet=%C2%BB&sort=date&name&showadd"></script>
Summary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With