[thelist] Pop-up when user leaves site.

Colin Mitchell colin_mitchell at wgbh.org
Mon May 21 15:17:00 CDT 2001

Hey All - This is my first post here.  Hi all.  My name's Colin, and I work
at WGBH in Boston.  We produce Nova, Antique's Roadshow, Frontline, yadda
yadda yadda, and I work on the local website.

Anyway, I have some code that does what you ask for.  But first, a warning:
doing this is annoying as heck to your users.

We redesigned our website last summer, and chose to have a 'floating
navigation' popup whenever a user left our site, and went to either a PBS
site, an NPR site, or a section of our own site that wasn't linked into the
new site.  We made this choice because we wanted to give the user a chance
to get back to our site once they had floated around somewhere else.
However, I have definite issues against doing it if it can all be avoided.

Anyway, what we do is this:  we have a wgbh.js file that gets included into
every page.  It sets an event handler, and includes the functions that get
called when the user leaves the page.  You can probably cut out the
externalLink function - that's where I check to see if this is a URL that
should get the floating nav.  Other than that though, this code should
essentially work out of the box.

Once again, I warn you against doing this unless you really feel it's

Here's the code:

// lets initialize some stuff here

var myHost = "www.wgbh.org";
var myPath = "/";

function popHelper() {

        var $url = 'http://' + myHost + myPath + 'floating_nav.html';

        myHeight = 81;
        myWidth = 681;

        yPos = screen.availHeight - myHeight - 20;

        optionStr = "scrollbars=no,location=no,width=" + myWidth +
",height=" + myHeight + ",screenY=" + yPos;

        helpWindow = window.open( $url, "NavBar", optionStr );

} // pophelper

// Event catching goes here...

var fNetscape = navigator.appName.indexOf("Microsoft") != -1 ? false : true;

if ( fNetscape == true ) {
        // For Netscape
        // set the event handler for clicks here
else {

        // for IE
        // set the event handler for clicks here

// we need to check for two types of links here
// - true external links
// - internal links that are to static, old pages
function externalLink( url ) {

        externalPages = new
","interactive.wgbh.org", "main.wgbh.org");
        internalPages = new

        var s = String(url);

        for ( var i = 0; i < externalPages.length; i++ ) {

                var re = externalPages[i];

                if ( s.search(re) != -1 ) {
                        return 1;

        } // for

        for ( var i = 0; i < internalPages.length; i++ ) {

                var re = internalPages[i];

                if ( s.search(re) != -1 ) {
                        return 1;

        } // for

        // no luck, so return 0
        return 0;

} // externalLink

function checklink(e) {

        // in IE, the event isnt passed to the handler.  This will take care
of that.

        if ( fNetscape == false ) {
                e = window.event;
                url = e.srcElement;
        else {
                element = e.target;
                url = element.href;

        // element should be an object of type Link
        if ( url && externalLink( url ) ) {


on 5/22/01 7:16 AM, CDitty at mail at redhotsweeps.com wrote:

> Not impossible, per say....You could add some JS code to each link that
> leaves your site that will call you JS popup function.  That is the only
> way I can see it done.  Talk about a real pain in the a** if you have a lot
> of external links.  Ouch.
> Another way would be to open a frame.   Have the top frame be 1 pixel
> high.  And just do 1 popup onload.   Just a thought.
> Chris
> <tip - Movie>
> Ok, not really a tip, but it's the best thing I can think of this early.
> Go see Shrek.  It was FUNNY.  Worth every penny.  Not really for
> kids but nothing that would really embarrass the parents.
> </tip>
> At 07:10 AM 5/21/2001, you wrote:
>>> I want to have a pop-up window come up when a user leaves my website.
>>> I have found several scripts that work when a user leaves a "page", but I
>>> only want the pop-up to come up when they leave the "site".
>>> Know what I mean?
>> In practice this can't be done, because you cannot find out if the new
>> page is from a new site. If the page is in another site you're not allowed
>> to read out the location, so you cannot tell the location of the new page.
>> So: this is impossible.
>> ppk
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt ! 

More information about the thelist mailing list