PROGRAMMING SOLUTIONS

Monday 27 April 2009

Add JavaScript in blogger (blogspot) post

Summary:
This post talks about why javascript sometimes does not work in blogger post and how to make it works.

Javascript code works well in HTML/Jscript gadgets, so it is no need to talk of this. Here we focus on Javascript in a post.

Let's start with an example. I added this SWFObect Javascript code to embed a flash video player generated by Moyea Web Player (http://www.playerdiy.com/ ) to show videos in my blog post and it was not working:


Player will show here



To my strange is that this code works in my Dreamweaver or other HTML editor. But why does not work in blogger?
I tried many other code and then I found this javascript code work well in blogger post:

Test


After this, I look carefully at my blogger post source (Edit Html):


Player will show here



There is a problem. In almost each new line. Almost Every time you have new line, blogger editor adds
tag. Because of this
tag web browser can't execute jscript.

So correct solution for my problem should look like this:

Player
will show here


To work well javascript in blogger post should be in one line.