Forum Moderators: open

Message Too Old, No Replies

Exit message

How do I give visitors an exit page or message

         

Adam5000

8:14 pm on Mar 9, 2008 (gmt 0)

10+ Year Member



On my website and I'd like to give visitors an exit page or message when they leave. For example, if a visitor is viewing one of my pages, and then goes to a page that's not part of my website, say Google, before they go, I'd like to give them a page or message that reads "You have now left my website." This page or message would hold for about five seconds and then they would be on their way. But I'm not exactly sure how to do it. Help!

gergoe

9:05 pm on Mar 9, 2008 (gmt 0)

10+ Year Member



Well, that's something I'd avoid. You could use the window's onunload event handler to do something when a page is being unloaded, but that's triggered always, regardless of the destination url, even if your page is just being reloaded. And there's no way to find out what is the destination url.

What you could do is to alter your links, if any of the links are pointing to an external page, change it (on the server-side preferably) in a way, that it goes to a sort of jump page first, or it involves a javascript function. From then on, you can do whatever you want with links pointing to external pages (either with javascript, or with a sort of jump page).

Adam5000

10:05 pm on Mar 9, 2008 (gmt 0)

10+ Year Member



I thought about that too. On some of the pages I'm going to put an exit link that takes the visitor to an external page, for example Google. And the thought was to have the exit link first take them to a "You have now left my site" page, and then after five seconds, forward them to the Google home page. How would that work?

Adam5000

10:17 pm on Mar 9, 2008 (gmt 0)

10+ Year Member



Here's another thought. I notice that all the pages in any particular web site always have the domain name in them for that site. For example for the home page www.mywebsite.com, then for pages 2 and 3 www.mywebsite.com/page2 and www.mywebsite.com/page3. Can I somehow key on that. The external destination page could be known after the visitor clicks on the link to it.

gergoe

10:48 pm on Mar 9, 2008 (gmt 0)

10+ Year Member



Here's another thought. I notice that all the pages in any particular web site always have the domain name in them for that site. For example for the home page www.mywebsite.com, then for pages 2 and 3 www.mywebsite.com/page2 and www.mywebsite.com/page3. Can I somehow key on that.

In a fact, not. An URL van be absolute or relative. A relative url does not contain the whole address, it might not have the domain name included for example, or part of the path is not defined as well, in these cases we talk about relative urls. An absolute url always starts with the protocol definition, for example "http", followed by the "://" separator.

In the case of a relative url, the browser resolves it into an absolute url, based on the location of the current page, in the following way (suppose the browser has the http://www.example.com/foo/bar/index.html loaded):

  • index_in_bar.html - http://www.example.com/foo/bar/index_in_bar.html
  • ../index_in_foo.html - http://www.example.com/foo/index_in_foo.html
  • /index_in_root.html - http://www.example.com/index_in_root.html
  • /foo/index_in_foo.html - http://www.example.com/foo/index_in_foo.html
  • http://www.example.com/index_in_root.html - http://www.example.com/index_in_root.html
  • http://www.google.com/ - [google.com...]
  • www.google.com - http://www.example.com/foo/bar/www.google.com (!)

The top four ones are relative urls, while the next two ones are absolute urls, and the last one is also considered to be relative url by the browser, because it does not include the http:// protocol definition, and even the path information is not present, so it resolves to a very funny url.

So, to determine whether an url is external or internal, you need to first examine that it starts with [,...] and that the hostname (www.example.com) is not from your website. if the above conditions are met, the link is pointing to an external website.

How you can check all your links? Using JavaScript you can make a function, and instead of using <a href="http://www.example.com"> do <a href="javascript:jumpTo('http://www.example.com');">, and within the jumpTo function you can check the url, if it's an internal one, jump to that url, when external, display your message (some way).

You can do this on the server side as well (works better, even with javascript disabled - some users tend to disable that), then look around in the documentation in the programming language you are using (php, asp, etc).

There's a different approach using JavaScript, but it is more difficult. After the page loads, you run a javascript code, which 'scans' your html page, and alters the <a> elements as necessary, but this requires fair knowledge of DOM and JavaScript.

The external destination page could be known after the visitor clicks on the link to it.

Nope. When the user click on a link, your website will not be notified in any way about the destination url, there's simply no way to find that out, unless you prepare a function for that, as I mentioned above.