02 Mar, 2003
Launching new windows, or brining focus to windows already launched…
Posted by: Jennifer In: Scripts
This partially in response to some modification requests to the smilie launch… This script will launch a new window. If/when it looses it's focus (ie. it's in the background) if the person clicks the link again, rather than launching a *new* window, or appearing to do nothing at all, this will bring the (previously launched) window to the front – or launch a new one if it had been closed…
So, first, in response to the "Lazyman's Smilies" – use this instead to launch your smilie palette (a minor update was added so that you don't lose your "spot" on the page):
<a name="smilieLaunch"></a>
<a href="#smilieLaunch" onClick="openAWindow('/smilies/index.php','smilies','scrollbars=yes,width=400,height=300')">Add a smilie</a> (launches smilie 'palette')
Then any page that you have the ability to launch that smilie palette, put this code somewhere between your <head> </head> tags…
<script language="JavaScript">
<!–
var ANewWindow = null; // new
function openAWindow(theURL,winName,features) { //v2.0
// check if window already exists
if (!ANewWindow || ANewWindow.closed) {
// store new ANewWindow in global var
ANewWindow = window.open(theURL,winName,features);
} else {
ANewWindow.location = theURL;
ANewWindow.focus();
}
}
//–>
</script>
As well, you'll now want to make it so that the smilie palette doesn't automatically close once somone clicks on a smilie… so in that smilieIndex.txt code… comment out the following two lines:
self.opener.window.document.<? echo $commentsFormName; ?>.<? echo $commentsTextName; ?>.focus();
window.close();
like this:
// self.opener.window.document.<? echo $commentsFormName; ?>.<? echo $commentsTextName; ?>.focus();
// window.close();
[ Thanks to Doc for his help and Sandman for his tutorial on using this on your edit_entry.tmpl ]
[ an additional note – I did NOT write the javascript function… a co-worker at a former job I had did ]