ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Displaying Message When Leaving the Site?

July 24, 2008 12:36pm

Subscribe [1]
  • #1 / Jul 24, 2008 12:36pm

    trebor79

    9 posts

    I’m building a site for a bank and as part of their regulations, a notice/message needs to be displayed anytime you click an external link and leave their site.

    When a person clicks a link that will take them away from the bank’s site, I’d like EE to display a nice message that refreshes/redirects to the link after a few seconds (ala EE contact form).

    I was thinking something along the lines of a conditional that checks if the domain name in the link is the same as the bank’s site, and if not, displays the message and then redirects to the external site a few seconds later. But I’m not sure how to make that work.

    I’m new to EE, so bare with me. I’ve searched the forums and knowledge base, etc and haven’t found any mention of this. I wasn’t sure what to search for, though. Any help would be appreciated 😊

  • #2 / Jul 25, 2008 3:17pm

    trebor79

    9 posts

    Any ideas or suggestions?

  • #3 / Jul 25, 2008 4:40pm

    CI Lee

    343 posts

    Kinda like this?

    function goodbye(e) {
        if(!e) e = window.event;
        //e.cancelBubble is supported by IE - this will kill the bubbling process.
        e.cancelBubble = true;
        e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
    
        //e.stopPropagation works in Firefox.
        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
        }
    }
    window.onbeforeunload=goodbye;

    Taken from Here

  • #4 / Jul 25, 2008 5:07pm

    trebor79

    9 posts

    CI Lee: Thanks for the reply. That would probably work for the message part. But I also need it to be automatically triggered on links that go to external sites.

    The message has to appear on every link that goes to a page/site that’s not on the bank’s domain (for legal reasons).

    I would like it to check if it’s a link to a page on the same domain as the site, and if not, only then display the message. I don’t want to have to manually add it to every link to an external site - just trigger the message code when applicable.

  • #5 / Aug 05, 2008 1:16am

    trebor79

    9 posts

    Just thought I’d follow up on what I found. I ended up using some jQuery-goodness to show the dialog.

    jqModal

    I used the code for example #6 on jqModal’s site.

    jqModal doesn’t seem to be able to automatically tell whether a site is an external site or not, but it does work for my purposes. The only thing that needs to be added to a link is

    class="confirm"

    .

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases