Monday, March 24, 2008

Blogger how to - insert a script in blog - method 2

Ok, so in the first part, we have inserted a script into our blogger xml template by hosting that script on some external domain and then linking it in the template.
Now we will learn something about the source code of the xml template.

The second method to insert a script is by inserting the code itself into the xml source.
This is not an easy part, since the Blogger parser will scan the xml template.
The XML source code is a little different than a script code, that's why the Blogger parser will strip away a good piece of your script, making it useless and many times, screwing up the blog xml template itself.

So, for this method, you must be very carefull not to erase something important from the template, or even to lose the xml code.

First, before editing the xml code, backup your existing template. (click the "Download full template" link from the Layout-Edit HTML page)
This must be the first step you make every time you are editing something inside the source code.

To have much less chances to destroy your blog, keep in mind that this method must be used only for short, clear and not so aggressive scripts (without complicated mathematical and comparing operations).

All this said, the manner in which you will insert the script code is the following:
insert the script between <script type="text/javascript"> and </script> tags from inside the <head> </head> section of the xml layout.

Example:
<head>
...
<script type="text/javascript">
...your script here...
</script>
...
</head>

As an example on what's good a script for, click onto the following picture and you may see a beautiful enlarge/fade effect.

example picture for an enlarge/fade effect

0 comments: