The whole idea behind a widget is that you have a javascript file that writes content to a specific HTML tag (through using a specific ID). The JS can communicate with Server-side things through ajax making it able to use cookies and such to get more interesting content.
Here si a VERY simple example of a widget:
script.js:
CODE
function init(){
var obj = document.getElementById("ThisIsTheWidget");
obj.someEvent = function(){
this.innerHTML = "HAHA";
}
obj.onSomeOtherEvent = function(){
this.innerHTML= "HEHE";
}
}
init();
Main HTML file that is using the widget:
CODE
<html>
<head>
<!-- STUFF HERE -->
</head>
<body>
<!-- MORE STUFF HERE -->
<div id="ThisIsTheWidget">
<script src="script.js"></script>
</div>
<!-- AND STILL MORE STUFF HERE -->
</body>
</html>
Basically all this does is make the div with the id="ThisIsTheWidget" change its innerHTML on 2 random (and at this time non-existant) events.
As I said earlier you can use ajax to communicate with server sid elanguages to enhance what widgets are capable of doing.
Hope that helps.