Friday, September 3, 2010

How to open a new console when someone enters or leaves your site

You've probably seen this on some web sites. When you enter the site, but more frequently when you leave the site, a console pops up with some additional info or ads, or a poll etc. This can be done using Java script.
To Open A Console When Someone Enters Your Site:
<script language="JavaScript">
<!--'','HB','toolbar=1, location=1,status=1,menubar=1, scrollbars=1,resizable=1, width=500,height=300');
// -->

Just place the above code within the BODY tags.
To Open A Console When Someone Leaves Your Site:
Place the following attribute in the <body> tag: onunload="leave()"
For example:
<body bgcolor="#000000" onunload="leave()">
Place the following code between the "</head>" and <body> tag.
<script language="JavaScript">
var exit=true;
function leave()
if (exit)
open("",'HBexit','toolbar=1,location=1, status=1,menubar=1,scrollbars=1,resizable=1, width=500,height=300');
// -->

Now you will have a console popping up everytime you leave the site. So make sure you use the below attribute in the <a href> tag on links to avoid the exit console from popping up on sponsors and other links where this is not desired.
For example:
<A HREF="" onclick="exit=false">
NOTE: Make sure you keep the long string of codes intact; if you break them, they won't work (and that's why this page is different also). To customize the codes, replace the URL in red with the one of your choice. Oh, don't overdo this because your visitors will get annoyed.

No comments:

Post a Comment