Solved

Intermittent Page to Warn Visitors They Are Leaving Website?

Posted on 2012-04-03
5
327 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now