1. Cautare intr-un array sau obiect
function in_array(needle, array) { var thisi = 0; for(thisi in array) { if(array[thisi] == needle) return true; } return false;}// alert( in_array('someNeedle', new Array('1', 'someNeedle', '30')) );
2. Inca se mai folosesc pop-up-urile.
function windowOpen(url, opt) { opt = opt || {}; opt.url = url; opt.width = opt.width || 500; opt.height = opt.height || 300; opt.status = opt.status || 'no'; opt.toolbar = opt.toolbar || 'no'; opt.location = opt.location || 'no'; opt.menubar = opt.menubar || 'no'; opt.directories = opt.directories || 'no'; opt.resizable = opt.resizable || 'no'; opt.scrollbars = opt.scrollbars || 'yes'; opt.name = opt.name || '_blank'; opt.top = opt.top || 20; opt.left = opt.left || 100; opt.channelmode = opt.channelmode || 0; /* and, make it open */ window.open(opt.url, opt.name, 'width='+opt.width+', height='+opt.height+', status='+opt.status+', toolbar='+opt.toolbar+', location'+opt.location+', menubar='+opt.menubar+', directories='+opt.directories+', resizable='+opt.resizable+', scrollbars='+opt.scrollbars+', top='+opt.top+', left='+opt.left+', channelmode='+opt.channelmode); return false;}// windowOpen('myPage.php', { width:500, height:300, top:30 });
3. Refresh iframe (trebuie sa-i dati un ID)
function iframeRefresh(id, address) { var ifr = document.getElementById(id); ifr.src = address; return false;}// iframeRefresh('myFrmae', 'http://google.com')
4. Easy way to show flash movie
function writeFlash(opt) { opt = opt || {}; opt.url = opt.url || ''; opt.width = opt.width || 0; opt.height = opt.height || 0; opt.wmode = opt.wmode || 'transparent'; opt.flashVars = opt.flashVars || ''; document.write('<'+'object type="application/x-shockwave-flash" data="'+opt.url+'" width="'+opt.width+'" height="'+opt.height+'"'+'>'); document.write('<'+'param name="movie" value="'+opt.url+'" '+'/'+'>'); document.write('<'+'param name="allowScriptAccess" value="always" '+'/'+'>'); document.write('<'+'param name="flashVars" value="'+opt.flashVars+'" '+'/'+'>'); document.write('<'+'param name="wmode" value="'+opt.wmode+'" '+'/'+'>'+'<'+'/'+'object>'); return false;}// writeFlash({ url: 'myMovie.swf',width:300,height:200 })
5. Merge two objects
function mergeObjects(ob1, ob2) { var attrname; for (attrname in ob1) { ob2[attrname] = ob1[attrname]; } return ob2;}// var obj1 = { a:'b', c:'d' };// var obj2 = { m:'b', c:'z' };// var main = mergeObjects(obj1, obj2);// alert(main.c);