Wednesday, February 3, 2010

swfObject


swfObject is the small javascript library (10Kb / GZIPed: 3.9Kb), used to embed flash content  in your html page.
Major Advantages:
1.       1.  It detects if the browser has flash player to play the flash content.
2.      2.  It detect flash player version.
3.       3. Can be helpful to display an alternative content if your browser does not have flash player installed in it.
4.       4. SEO optimization of flash content.
5.       5. Better way around for <embed> tag which is not w3c valid tag.

How to Use?
1.       Download the library.
2.       Add it in your app.
<script type="text/javascript" src="swfobject.js"></script>
3.       Add some container in your html page which could hold the flash content.
e.g. <div id=”flashContent”>&nbsp;</div>
4.    <script type="text/javascript">
var so = new SWFObject("movie.swf", "mymovie", "400", "200", "8", "#336699");
so.write("flashcontent");
</script>

What each parameter means:
var so = new SWFObject(swf, id, width, height, version, background-color);

Related Links:

Saturday, November 7, 2009

jQuery.noConflict()

There are different JavaScript libraries such as jQuery,mootools,ajax etc available which helps us to add functionalities to our web applications.
Hundreds of plugins built using those libraries are making our tasks easy. So without actually peeping into the code we use those plugins.
Now, the problem arises when these libraries are used together.

I stuck in the same problem when I was implementing jquery in my application which already had lighbox implemented in it.
After researching a lot I figured out that prototype.js which was used for implementing Lightbox and jQuery.js in my application were conflicting.

The real problem was both libraries were using '$' as their main function name. Hence one library was breaking the behaviour of other library.

for e.g. in jquery we use :
$(function(){
---
---
});

Here '$' represents jQuery. Similarly in prototype.js for lightbox '$' was used which was representing its main function.
jQuery has provided us the solution to get rid of this problem. Simply use noConflict() function immediately after jQuery.js.
When you use noConflict(), jQuery will return $() to its previous owner and you will need to use jQuery() instead of shorthand $() function.

so it can be written as
jQuery(function(){
---
---
});

else...

var j=jQuery.noConflict();

so,
j(Function(){
--
--
});

So now, jQuery is compatible with other javascript libraries and can be used easily.