Home » » Add JavaScript in blogger (blogspot) post

Add JavaScript in blogger (blogspot) post

Written By anggit13 on Thursday, July 2, 2009 | 10:48 PM

Blogger 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:

<script type="text/javascript" src="swfobject.js"></script>
<div id="flashcontent">Player will show here</div>
<script type="text/javascript">
var so = new SWFObject('mwplayer.swf','player','500','450','9');
so.addParam('wmode','opaque');
so.addParam('quality','high');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.write("flashcontent");
</script>


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:

<a onclick="alert('This works.')" href="#" >Test</a>


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

<script type="text/javascript" src="swfobject.js"></script>
<div id="flashcontent">Player will show here</div>
<script type="text/javascript"><br />var so = new SWFObject
('mwplayer.swf','player','500','450','9');<br />so.addParam
('wmode','opaque');<br />so.addParam('quality','high');<br />so.addParam
('allowfullscreen','true');<br />so.addParam
('allowscriptaccess','always');<br />so.write("flashcontent");<br
/></script>


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

So correct solution for my problem should look like this:

<script type="text/javascript" src="swfobject.js"></script><div id="flashcontent">Player
will show here</div><script type="text/javascript">var so = new
SWFObject'mwplayer.swf','player','500','450','9');so.addParam('wmode','opaque');
so.addParam('quality','high');so.addParam('allowfullscreen','true');so.addParam
('allowscriptaccess','always');so.write("flashcontent");</script>


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

Here is example of JavaScript code that works(The player works but videos are deleted so you couldn't see the videos in the player):

Player will show here
Share this article :

0 komentar:

Post a Comment

Powered by Blogger.
 
Support : Best Phone Reviews | Multimedia Zone
Copyright © 2013. Update News Smartphones Gadget and Android - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger