Step 1: Create a Widget
If you want to create a Widget Installer, obviously the first thing you need to do is to create the widget itself. A real one-click-installable widget should contain all the necessary code. So if there is javascript-code that need to be installed, try to embed it inside the widget.
Just for the fun of it, let's create a Random Quote Widget (thanks Annie).
Open your Blog's template, add a HTML/Javascript page-element, set the title to "Random Quote", and add the following javascript to its content:
<script language="JavaScript">
//store the quotations in arrays
quotes = new Array(6);
quotes[0] = "So many cats, so few recipes.";
quotes[1] = "Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.";
quotes[2] = "That's not a haircut. That's a cry for help.";
quotes[3] = "The last thing I want to do is hurt you. But it's still on the list.";
quotes[4] = "Some days it's just not worth gnawing through the leather straps.";
quotes[5] = "Doing for blogging what Ghengis Khan did for social work.";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("\n");
document.write(quotes[index]);
//done
</script>
This code is a javascript script. What it does is easy to understand. It creates a data structure called an array, with six elements. The elements are number 0 through 5. Then it calculates a random number from 0 to 5, and displays the array-element with this index. This is just plain javascript.
Save the widget, and see how it works. Every time you reload your page, a new quote will appear.
Step 2: Understand how widgets can be added to Blogger
Now that you have created your widget, you have to learn how you can add a widget to Blogger. That is explained in the Blogger Help pages. What you have to do is that you have to create a FORM. A form is a HTML-element, and can have input boxes, radio-buttons, check-boxes, buttons, and so on.
Step 3: Create a Widget Install Button
Now we will create our own Install Button using a form. Our form has to look like this:
<form method="post" action="http://beta.blogger.com/add-widget">
<input name="widget.title" style="display:none" value="Random Quote"/>
<textarea name="widget.content" style="display:none;">
<script language="JavaScript">
//store the quotations in arrays
quotes = new Array(6);
quotes[0] = "So many cats, so few recipes.";
quotes[1] = "Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.";
quotes[2] = "That's not a haircut. That's a cry for help.";
quotes[3] = "The last thing I want to do is hurt you. But it's still on the list.";
quotes[4] = "Some days it's just not worth gnawing through the leather straps.";
quotes[5] = "Doing for blogging what Ghengis Khan did for social work.";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("\n");
document.write(quotes[index]);
//done
</script>
</textarea>
<input type="submit" name="go" value="Add widget to your blog"/>
</form>
Let us take a closer look at this form. As usual with HTML, there is an opening-tag <form> and a closing-tag </form>. The content of the form has to be posted to the url http://beta.blogger.com/add-widget. This information is added to the form opening tag. The form has to contain 3 elements: the widget title, the widget content, and a button to submit the form to Blogger. The widget title is set using an Input Field in the form. The name of this input field has to be set to "widget.title", so that Blogger knows it is the widget title. The value of this field can be anything you like. The value is displayed on your Blog as the widget's title. In this example I set it to "Random Quote", but it could also be "A Very Deep Thought".
The widget content is the javascript-code from step 1. We put this javascript inside a textarea-field. The textarea has an opening tag and a closing tag. Put the javascript between these two tags. Inside this form, we have to make sure that the javascript is handled as text, and not as javascript. Therefore, replace all < with < and replace all > with >. The name of the textarea is set to "widget.content" so that Blogger knows that this field contains the widget content. The style of both the title input and the textarea is set to display:none, so that the user doesn't see them (but don't worry, it is there all the same).
Finally, there is an input button, the value is displayed as the button text.
If you copy this form and paste it to the end of the widget-code that is already in your sidebar, you will get a button below the widget, and clicking the button will install the widget to your visitor's blog.

This is what people say:
Please, example with feed (and images for title customized of feed, please).
nothing, nothing, already are. A million thanks, widget beastly.
Sorry for the Flood. I can do, which widget after installed in another blog, to include button (on the widget installed) so that they can again install (forming a chain that extends to me more to blogs) feed of my blog from new blog.
Hans, the callback of JSON Feed from Installer Widget recent posts, make problems:
http://pulpcomic.blogspot.com/feeds/posts/default?alt=json-in-script&callback=showrecentposts
"error XML: The reference to entity "callback" must end with the ';' delimiter."
@Braniac: I cannot reproduce the XML-error. If you go to my widget installer page, and click the install-button, the installer will work as it should, no errors. So: what exactly did you do that caused the XML-error?
I recently found this blog and I've found it quite helpful. I do have one question. I have a blog here: http://searchintelligence.blogspot.com/index.html
and I posted the widget into the html/ java on the left hand side. However, I cant get more than 16 quotes to display.
Not wanting to spam your feedback, I was wondering if you could give me a little advice.
Thank you.
@JP Sherman: you can add new quotes to the list, by adding lines to the code, like: quote[16] = "Help, this is another quote!"; and quote[17] = "I am out of quotes";. They will be displayed when the random number generator generates their number.
Hello, i am a first time visitor to your blog. Can you tell me how to create a sidebox, which contains all the labels? I use Blogger Beta, with a Blogger Classic Template.
Check out my blog at Digital Dreams.
I do not want to switch my template either. Is there a way to create the box manually? I shall not have more than 8-10 labels. So creating manually is not a problem.
@ Hans
Thanks again for your help. That solved the issue.
I input the code and it seemed to work but my quotes are not viewable. I just get the title or the button but no quotes.
This is great! I didn't even see any of this information on Blogger's dev site. I used it to make an installer for my site Jauntlet.com. Thanks!
FYI, this person is giving away templates with your hacks already added. Do they have your permission to distribute your work?
http://web-messengers.blogspot.com/2006/12/3-column-minima-templates-modded-for.html
@Tom: thanks!
@Alice: my work is under a creative commons license. And he has added a link to my blog. Thanks anyway
Thanks for the help!
Share your thoughts!
Feel free to post your questions, remarks and comments here. Moderation is set for this blog, so your comments will appear in due time.
Look who's linking here!
0 Backlinks point here