Thoughts on Web Development
Opening a browser window Friday, May 06, 2005 1:08 PM
Recently, one of my customers asked for a link which would crate a small popup window displaying an image of their product and a button to close the window from the product catalog window. I don't do a lot of work with JavaScript but thought I'd document the script in a blog entry.

On the product catalog page you want to include a link which calls the javascript:

<A href="javascript:popupWindow('contents.html',300,250)" onmouseover="window.status='A picture of contents';return true"
onmouseout="window.status=''">picture of contents</A> )

In the link, you call the javascript funtion popupWindow with some parameters. The code is pretty self-explanatory. There is a var declared for the new window with a scope so the needed functions can see it. Then you set up the attributes for the contents window, you close the window if it's already opened, you open it, and then set the focus to it. The functions look like this:

/* first, declare the variable newWin that will be used for the new window object, so that we can refer to it later. */
var newWin;

/* the basic window opening function. */
function popupWindow(url,w,h)
settings = '"toolbar=no, directories=no,menubar=no, scrollbars=no, resizable=no, status=no,width='+w+',height='+h+'"';
/* calling the closeWindow() function. */
newWin = window.open(url,'newWin',settings);

/* the closeWindow function */
function closeWindow()
if (newWin && !newWin.closed)

In the contents window, you need the following line to allow the user to close the window by clicking on the link "Close window":

<a href="javascript:self.close()" class="FormText">Close window</a>

I always find it cool all the things you can do on the client side but I have to say, after working in C#, I do not like how sloppy client script is on the browser side.
0 Comment(s) Add comment
© LimberTech 2016