1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirect url after close button is pressed

Discussion in 'Hire a Freelancer' started by Thornus, May 22, 2017.

  1. Thornus

    Thornus Newbie

    Apr 13, 2017
    Likes Received:

    Like the title says,I need redirect user after pressing close button in browser.In one thread here I found this code.
    <script type="text/javascript">
    function addEvent(obj, evt, fn) {
        if (obj.addEventListener) {
            obj.addEventListener(evt, fn, false);
        else if (obj.attachEvent) {
            obj.attachEvent("on" + evt, fn);
    addEvent(window,"load",function(e) {
        addEvent(document, "mouseout", function(e) {
            e = e ? e : window.event;
            var from = e.relatedTarget || e.toElement;
            if (!from || from.nodeName == "HTML") {
                // stop your drag event here
                // for now we can just use an alert
                //alert("left window");
            window.location = "http://www.google.com/"

    It works,but not exactly.It redirects user after his mouse is leaving and not after close button is pressed.
    Also I need this script will work
    -for mobiles
    -redirect specific url to other specific url. So it means each my post will redirect to different url/I use WP

    I just need working script and site url + destination url I allways change by myself.
    So please guys if someone of you knows how you can send me pm or leave solution here for other members.

    Thank you