Solved

Intermittent Page to Warn Visitors They Are Leaving Website?

Posted on 2012-04-03
5
332 Views
Last Modified: 2012-04-18
I want to warn visitors they are leaving my (Drupal) website when they click on certain links (that lead to other external sites).

Is there a module for this? Or what other approach?
0
Comment
Question by:sandshakimi
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
junipllc earned 250 total points
ID: 37801759
there is a module for 6 but I'm not sure if it has been ported to 7. I'm not at an actual desktop machine but when I get to one i will check for it. there is also a very simple jquery solution you can use.

either way it's easy to do. I should be off of this awful phone interface and be able to check in a bit for you.

mike
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 37801918
I have done this in the past by using a separate "goodbye" page in place of the conventional anchor tag.  You pass it a URL argument of the destination page.  If the destination is off the site, it loads a message telling the client that they are exiting the site.  I believe you can also do this with JavaScript.  You might be able to adapt this function to meet your needs.
<?php // RAY_leaving_the_site.php
error_reporting(E_ALL);

function ELink($url, $text=NULL, $class=NULL, $target=NULL)
{
    // IF NO TEXT, USE THE URL
    if (!$text) $text = $url;

    // PREPARE THE LINK TEXT
    $link = '<a';
    if ($class)  $link .= ' class="'  . $class  . '"';
    if ($target) $link .= ' target="' . $target . '"';
    $link .= ' href="' . $url . '">';
    $link .= $text;
    $link .= '</a>';

    // IF THIS IS AN EXPLICIT LINK
    $rgx
    = '#'          // REGEX DELIMITER
    . '^'          // STARTS WITH
    . 'http'       // EXPLICIT URL
    . '#'          // REGEX DELIMITER
    . 'i'          // CASE-INSENSITIVE
    ;
    if (preg_match($rgx, $url))
    {
        return "CLICK HERE TO LEAVE THIS SITE: $link";
    }
    // IF THIS IS A RELATIVE LINK
    else
    {
        return $link;
    }
}

// USE THE FUNCTION
echo PHP_EOL . '<br/>' . elink('http://www.google.com');
echo PHP_EOL . '<br/>' . elink('http://www.google.com', 'Google', 'offsite', '_blank');
echo PHP_EOL . '<br/>' . elink('index.php', 'Home Page');

Open in new window

0
 
LVL 12

Expert Comment

by:junipllc
ID: 37808775
If you don't actually need the intermediary page but instead just a warning, then this is the module I was talking about, and it works in D6 and D7:

http://drupal.org/project/extlink

Mike
0
 

Author Comment

by:sandshakimi
ID: 37850825
Ray, is this the intermediate page that visitors will be directed to before leaving the site?
0
 

Author Closing Comment

by:sandshakimi
ID: 37861348
To makes simpler, I decided to use a static php page. Thanks
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP installation issues 11 59
how can i Return this word's max repeat count? 2 16
mysql date time 14 29
How can I make a javascript to show drop down 4 12
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question