Create Javascript alerts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreemathy2000
    New Member
    • Oct 2007
    • 40

    Create Javascript alerts

    My requirement is to display, via an overlay, a message informing the user they are leaving mywebsite.com and allow them to continue or cancel. This will only occur if the user is leaving the mywebsite.com site to go to an external site.

    There are links to other websites in my website. Whenver a user navigates away from my website, a alert has to be displayed.

    Is there any better option or sample code to do that.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use onbeforeunload, e.g.
    [code=javascript]window.onbefore unload = displayConfirm;
    function displayConfirm( ) {
    return "Are you sure that you wish to navigate away?";
    }[/code]Use it wisely otherwise it can be annoying.

    Comment

    Working...