Short Tag – Web Development Blog

Entries Tagged ‘Javascript’

Fancybox – width and height not working

Let’s say you have this code:

$.fancybox({
‘autoScale’ : false,
‘transitionIn’ : ‘none’,
‘transitionOut’ : ‘none’,
‘width’ : ‘680′,
‘height’ : ‘495′
});

If you use Fancybox like this the width and height of the window will not be 680×495. Instead the window will have almost the size of the browser window. This is an often encountered problem.
The solution is to remove the quotes from the width and [...]

Javascript function to trim any character

Today I want to share a javascript function that will trim any character from the beginning and the end of the string.
The function will trim all occurrences of the character from the beginning and the end of the string.

function trim_chars(str, char)
{

while (str.substr(0, 1) == char)
str = str.substr(1);

var nrt = str.length;
while (str.substr(nrt-1, 1) == char)
{
str = [...]

Cancel action on a link (do not reload the window on click)

When you are developing using javascript it is often you get to the situation where you want to do something with javascript when the user clicks on the link. The problem is that when the user clicks on the link the browser will reload the window (and you don’t want that).
1.) Disable reload using HTML

<a [...]

JQuery and Innerfade (slideshow plugin)

Jquery is a library of Javascript functions and classes that can make Javascript programming a lot easier. Cross-browser Ajax means one line of code with JQuery. Animations, moving objects are easy to do with Jquery.
And it’s absolutely free!
Official website:
http://jquery.com/
Now… what is innerfade?
Innerfade is a plugin for JQuery. You can use innerfade for slideshows. Innerfade [...]

getElementsByClassName in Javascript

This is a function that returns all the elements in the page that have the given class name.
Returns an array with the objects.

function getElementsByClassName( strClassName, obj ) {
var ar = arguments[2] || new Array();
var re = new RegExp("\\b" + strClassName + "\\b", "g");

if ( re.test(obj.className) ) {
ar.push( obj );
}
for ( var i = 0; i [...]

Set cookie with javascript

Sometimes is useful to set a cookie with javascript. You can use the function below.

function Set_Cookie(name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );

if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; }
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + [...]