May 18

Expandable sample

Say, you have an expandable menu (like the one in picture but the expansion is not Javascript driven) on the parent window and the parent window refreshes on every click of the node of the menu (the (+) and (-) kind of menus). You also have a “Close All” button on the parent window which is supposed to close all the child windows.

Ideally, you want to hold the names (or handles) of the child windows in order to close all the child windows when the “Close all” button is pressed. But since the parent window gets refreshed on menu node expansion, the Javascript array of child handles that i have disappears.

Bottom line, Javascript variables get reinitialized on page refreshes. But there is a workaround for this.

You can simply assign the array to a special variable called navigator.storedvariable

Something like,
navigator.storedvariable=windowNames; // windowNames is the array of names of the child windows.

This is the exact code i wrote for implementing the Closeall functionality

function closeChildWindows(){//retrieve all the names of childwindows
var childWindows = navigator.storedvariable;
if ( childWindows != null ){

//loop through each of the window
for (var k=0;k<childWindows.length;k++){
var openedWindowName = childWindows[k];

//Open all the child windows since we have already lost handles and then close again. The browser will open the child window in the same previous (stale) browser child window

winHandle = window.open(”,openedWindowName,’toolbar=0,location=0,width=2,height=2,scrollbars=no,resizable=no,directories=0,status=0,menubar=0′);winHandle.blur();
//as soon as you open, close them. So that the user doesnt realise that the same browser was used again

if( winHandle && winHandle.open && !winHandle.closed)
{
winHandle.close();
}
}//end of for loop

} // end of childwindows!= null
//after closing all windows, reinitialize navigator.storedvariable
windowNames=new Array();
navigator.storedvariable=windowNames;
}

Tags:

Mar 26

<script>
function saveImageAs (imgOrURL) {
if (typeof imgOrURL == ‘object’)
imgOrURL = imgOrURL.src;
window.win = open (imgOrURL);
setTimeout(’win.document.execCommand(”SaveAs”)’, 500);
}
</script>

<A href=”#”
ONCLICK=”saveImageAs(document.getElementById(’embedImage’)); return false” >save image</A>

<img id=”embedImage” src=”impossible.jpg” >
I am not the author of this code and i am really not sure where i picked up this script. But it works too good… only on IE

Tags:

Mar 08

I dont really speak javascript fluently.  Takes double the time to code than Java.  If you are like me or if you dont want to spend lots of time reinventing the wheel, then here is the list of some cool and commonly used javascript functions.  This site has some of the core methods in some popular javascript frameworks.  I personally used this getElementsByClassName() for a project.  Trim function, cross-browser ajax requests, searching an array are cool ones.

Ten_Javascript_Tools_Everyone_Should_Have 

Tags:

Feb 28

This is one awesome site I recently bumped into. Has so much of handly DHTML scripts that is ready to use. Most of them are AJAX based. Just download and plugin to your project.

Tags: ,

Feb 16

You can either create a html file with the following markups inside or click the link at the bottom of the post.

<html>
<body>
<script type=”text/javascript”>
var x = navigator
document.write(”CodeName=” + x.appCodeName)
document.write(”<br />”)
document.write(”MinorVersion=” + x.appMinorVersion)
document.write(”<br />”)
document.write(”Name=” + x.appName)
document.write(”<br />”)
document.write(”Version=” + x.appVersion)
document.write(”<br />”)
document.write(”CookieEnabled=” + x.cookieEnabled)
document.write(”<br />”)
document.write(”Platform=” + x.platform)
document.write(”<br />”)
document.write(”UA=” + x.userAgent)
document.write(”<br />”)
document.write(”BrowserLanguage=” + x.browserLanguage)
document.write(”<br />”)
document.write(”SystemLanguage=” + x.systemLanguage)
document.write(”<br />”)
document.write(”UserLanguage=” + x.userLanguage)
</script>
</body>
</html>

 http://www.arunma.com/browsercheck.html

Tags: