Monday, April 5, 2010

adding java script to your web

Did you ask yourself why in blogspot posts some javascript code works but in some cases don't. In this article you will find answer.

In HTML\Jscript gadgets jscript code work well. But this is not a case in posts.

For example I added this code to my blogspot post and it didn't working.

Test


I couldn't understand why this code doesn't working in blogspot post but in my HTML editor work.
Later I found that this jscript code works well in blogspot post:

Test


Conclusion is that if you put jscript code inside quote code will work. But I was not satisfied with this because I wanted to use jscript function and reuse function code (for example function showMessage() called from multiple places in post). And I didn't find answer how to put jscript function in quote.

Somewhere I founded tip to make jscript file with jscript code and put this file on the web. After that call jscript function addressing that file.

It shold look something like this:



I think that this method have too many steps and that is too complicated (you must upload you jscript file somewhere on the web and later call this file from your blogspot post).

After rejecting this method, I take look at my blog source (View source):



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

So correct solution for my problem should look like this:

Test


To work well javascript in blogger post should be in one line.
to learn jscript:-