How to Insert JavaScript inside Blogger Posts


Blogger Blogspot allows blog authors to include JavaScript-based widgets in the sidebars of the blog. But did you know that you can embed java scripts within the blog posts themselves?
It can be tricky to get the JavaScript to work within a blog post, but if you are patient and careful when editing and pasting the code, the possibilities are wide open. You can embed a simple JavaScript calculator, page view counter, date and time display, even some JavaScript-based animations. The trick is to make sure the code is embedded without any line breaks inside the post editor, or else Blogger will insert tags within your code, rendering it non-functional.
First create a new post or edit an old post in your Blogger blog, and click the tab for the HTML editor. These steps won't work if you are in the WYSIWYG editor.

Second Step write down your JavaScript code Locate the opening

<script type="text/javascript">
and closing
</script>




tags. If you see a<!-- unit after the opening script tag, delete it.  Likewise, if you find a //--> unit right before the closing script tag, delete it. These units are not necessary for most codes to function.  When they are present, they require line breaks, but unfortunately, line breaks are fatal when you try to embed the JS within a Blogger post.


Step 3 now edits the remaining code between the script tags to delete all line breaks. The nice thing about JavaScript is that line breaks don't affect how a program functions. They only serve to make the code look nice when you are developing or editing a file. When you finish this step, your code should just look like a wall of unbroken text between the opening and closing script tags.
Step4 If the Blogger post editor inserts more line breaks, go back and erase them all. As stated before, this requires patience!

Note of the Position your Javascript the Best Position to put Javascript Code for Site Functionality is: the End of the Body
The idea to put Javascript in the head has been largely diffused Simply because that the best way to keep Ordered and Readable your HTML Content... But now if you look at how HTML is Loading you will arrive to understand than it's Best to Load Before some Content and Images than Code. In Fact there is an Human Looking at the Screen and he Doesn't like so much Waiting in front a Blank or Messy Image


Publish your post to see if the JavaScript is functioning correctly. If not, you might have overlooked a line break, or accidentally erased a bracket. Just to prove that this method does work, below this is an example of a JavaScript calendar and simple digital clock embedded within a blog post on Blogger.


24 Hour Time

12 Hour Time






This is a JavaScript calendar. It shows you the current month's calendar, and the current day is highlighted! A very neat effect great JavaScripting!

Do you Like this story..?

Get Free Email Updates Daily!

Follow us!

1 comments:

Post a Comment