Solved

Intermittent Page to Warn Visitors They Are Leaving Website?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

808 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