- Navigation -
Popups and alerts

Sadly, because of adverts, most people have popups blocked these days. However, it's still nice to know how easy it is to use them, as they can be used, say, on a user's profile as an alert about a PM or something.
Popups are actually just more windows, opened specially to avoid all the toolbars and whatnot, and the function to open a window has a lot of properties like this to set. What we do is make a little function with most of them already set, to save time when we want to call it.

function openPopup(url,w,h) {
    var parString = "width=" + w+ ",height=" + h
       	+ ",toolbar=0,location=0,directories=0"
       	+ ",status=0,menuBar=0,scrollBars=0,resizable=0,topmargin=0,leftmargin=0 ";
    var winPop = window.open(url,"",parString);	  }	

As you can see, only the width, height and url need to be set by us now, and everything else is set to 0. You can experiment with turning things on, it's fairly obvious what most of them do. Once we've opened a window like this, the most useful thing to do next, then, is to be able to set properties of the original window. We can do it using the variable self.opener.
So, for example, if you wanted the user to click a link on the popup which would close the popup and link the main window to a new url, we could use this. A simple hyperlink would only change the url of the popup, but with javascript we can achieve what we want:

function winReturn(url){
	self.opener.location = url;
	self.close();
	}

Call that function in the hyperlink instead, and the popup will close and the main window will be linked to whereever. You can control other things in the same way - for instance you can have a popup with all the BBCode tags and when clicked on, they insert text into the form on the main window.

What about alerts, then? Very simply, the code is alert("Hello world");. More useful, though, is to ask a question. Yes and No is hard to get, but we can get an Okay or Cancel question like this:

if (confirm("Question to ask")) {
 actionToTake();
}

Still very simple really. And that's basically all I have to say on alerts and popups.

- mitxela

© Kousou Games 2007 lowfi version
Page created in 0.0092 seconds.
Valid XHTML 1.0 Transitional Valid CSS Powered by PHP