Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Leaving site notification" and CGI.HTTP_REFERER 1

Status
Not open for further replies.

MicahDB

Programmer
Jul 15, 2004
96
US
Greetings.

I come here from time to time with questions for all of you CF folks. I'm a web developer you was 'handed' a regional bank site that is unfortunately hosted on a CF server. No offense intended this is just not what I know. So I come here with simple questions for you'all. To this point I've managed to keep the site mostly in straight HTML and managed keep the client happy and cross browser compliant. BUT now I might need to try my hand at your world. I need a notification when a user attempts to leave the site using a link. Something saying "Your attempting to leave the bank site...". In reading online I think I need to use the CGI.HTTP_REFERER tag (or object or whatever you call it). But I also saw something that said some block that value from being sent (Norton Internet Security and Yahoo IE toolbar).

Any help and maybe a pointer to a tutorial would be MUCH APPRECIATED!!!!!!!

Thanks,
Micah
 
this sounds like more a javascript question. if the user leaves your site, there is nothing much you can do with the CF. However, with javascript, when a user clicks on a link, you can trigger an onClick event and do whatever you want with it.
hope it helps...

 
Thanks for the reply. Sorry, let me be more clear. What I would like to do is send a user to a page letting them know they're about to leave the bank site and ask them if they wish to continue. If they they do, they simply click the continue button and go the new site. However, if the do not wish to continue, I need to know which page they came from and that is where, I believe the use of CGI.HTTP_REFERER comes in. By passing the previous page to the "cancel" button, I can return the user to the previous page.

I don't want to use a simple html popup. Here is a good example of the page I'd like to send them to for them to decide...the functionality of the 'Return to BOA' button is what I'm looking for.


THanks,
Micah
 
There are two ways to do the "Return" button, and you'll need to do a little bit of conditional programming to get the "Leave" button working. It's not going to be that bad, and I thing that if you're already familiar with html, you should breeze right through it. Give ColdFusion a chance, I think you'll like it. :)

So, for the "Return" button, you can either use CGI.HTTP_REFERER, or you can do it with a simple JavaScript "History" link:
Code:
Using ColdFusion:
<cfoutput>
  <input type="button" value="Return to our site" onClick="parent.location='#CGI.HTTP_REFERER#'">
</cfoutput>


Using JavaScript:
<input type="button" value="Return to our site" onClick="javascript:window.history.go(-1);">
The JavaScript example would probably be better in this case, as it is basically the same thing as hitting the browser's "back" button. The CF example will acutally go to (and reload) the page again, and that may cause problems if the page is looking for some type of input variables.

Now, to figure out what link the person wants to go to...

Notice in the example that you gave us, at the end of the url there is this "?referredby=sipc". If you view the source of that page, you'll see that it is linking to the sipc website. What you'll have to do is create a link and URL string (like "?referredby=sipc") for every link leaving your website, and point them to something like "leaving.cfm". So, if you had a link from your site to the sipc site, it would look like this:
Code:
<a href="leaving.cfm?site=sipc">Go to SIPC website</a>
Then on "leaving.cfm", you would have the following:
Code:
<cfparam name="Url.Site" default="">
  <cfif Len(Trim(Url.Site))>
    <cfif Url.Site EQ "sipc">
      <cfset GoTo = "[URL unfurl="true"]http://www.SiteUrlHere.com">[/URL]
    <cfelseif Url.Site EQ "Something Else">
      <cfset GoTo = "[URL unfurl="true"]http://www.AnotherUrlHere.com">[/URL]
    <cfelse>
      <cfset GoTo = "">
    </cfif>
  <cfelse>
    <cfset GoTo = "">
  </cfif>

You are trying to leave our site!  If you must go, we understand, but we really wish you would stay!
<br>
<input type="button" value="Return to our site" onClick="javascript:window.history.go(-1);">
<br>
<cfif Len(Trim(GoTo))>
  <cfoutput>
    <input type="button" value="Leave our site" onClick="parent.location='#GoTo#'">
  </cfoutput>
</cfif>

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
ECAR,

That all makes perfect sense and is by FAR the best explanation I'm received from a post. Thank you for your help. I'll work on it this evening.

Thanks again,
Micah
 
No problem! I got to thinking about it, and I came up with a much simpler way to handle this.

If you're going to be dealing with a lot of urls, then the whole <cfif>,<cfelseif> approach can quickly get out of hand, and wind up being a pain every time you want to add a new link.

This would make the script a little more scaleable and easier to maintain. Whenever you create a new link, just make the URL string be part of the web address. For example, if you had a link to make your link like so:
Code:
<cfoutput>
  <a href="leaving.cfm?site=#UrlEncodedFormat('[URL unfurl="true"]www.somesite.com')#">[/URL] Go to this website</a>
</cfoutput>
Then, on your "leaving.cfm" page, simply have the following.
Code:
<cfparam name="Url.Site" default="">

You are trying to leave our site!  If you must go, we understand, but we really wish you would stay!
<br>
<input type="button" value="Return to our site" onClick="javascript:window.history.go(-1);">
<br>
<cfif Len(Trim(Url.Site))>
  <cfoutput>
    <input type="button" value="Leave our site" onClick="parent.location='[URL unfurl="true"]http://#UrlDecode(Url.Site)#'">[/URL]
  </cfoutput>
</cfif>
This will be much easier to maintain! When adding a new link, all you have to do is specify the web address in the link, and the CF page will automatically do the rest. However, the downside to this is that someone can tamper with the URL and change the link. But, since all it will do is create a link to that page, it shouldn't really hurt anything.

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top