Click to See Complete Forum and Search --> : Calling Function in If Exists Window


webbo_uk
02-01-2004, 08:29 AM
Hi All

I have a js function in a another page/window, what i need to be able to do is

1) check the window containing the function exists
2) if it does call the function (which works fine)
3) if it doesnt, create the window and then call the function

Any help would be greatly appreciated.

Many Thanks

Webbo_uk

buntine
02-01-2004, 08:59 AM
This shouldnt be too hard to achieve. Try doing something like this:


function call_funct() {
if (window.win_name) {
if (window.win_name.functionName) { //Does the function exist?
window.win_name.functionName(); //Call function.
}
} else {

//Open the new window in the center of the screen.
var pageHref = "page_to_open.html";
var center_t=(screen.height - pageHeight) / 2;
var center_l=(screen.width - pageWidth) / 2;
var pageHeight = 300;
var pageWidth = 400;
props='height=' +pageHeight+' ,width='+pageWidth+' ,top='+center_t+' ,left=' +center_l+' ,scrollbars=yes ,noresize';

show=window.open(pageHref, 'win_name', props);
show.window.focus();
show.window.functionName();

}
}


This function is fairly self explanatory.. Post if ya run into problems ;)

Regards,
Andrew Buntine.