离开页面时如何使用Jquery显示弹出式问卷调查 [英] How to show pop-up survey with Jquery when leaving page

查看:107
本文介绍了离开页面时如何使用Jquery显示弹出式问卷调查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户离开页面时在弹出窗口中显示调查.

I want to show survey in pop-up window when users leaves page.

所以我只想在他回答所有调查问题和/或关闭弹出窗口时才离开页面.我该怎么办?

So I want to leave page only when he answers all the questions of survey and/or close the pop-up window... How can I do that?

我尝试这段代码

$(document).ready(function () {
        function exitpop() {
            my_window = window.open("http://www.google.com", "mywindow1", "status=off,toolbar=off,location=off,menubar=off,directories=off,resizable=off,scrollbars=off,height=800,width=800");
            });
        }
        $(window).unload(function () {
            exitpop();
        });
    });

但是它被大多数浏览器阻止,并且不要暂停单击的操作(转到其他页面或关闭窗口). 最好的方法是什么?

But it blocks by majority of browsers and don't pause clicked action(going to other page or closing the window). What is the best way to do that?

推荐答案

尝试使用window.onbeforeunload事件..

在以下代码段中有个主意.我正在使用这种类型的代码在离开页面之前确认使用..这意味着它是关闭选项卡或刷新页面...

have an idea from the follow code snippet. i am using this type of code to confirm use to before leaving the page.. means either it is close tab or refresh the page...

但是您必须跟踪其刷新或关闭的时间.两者均与前卸载的含义相同. 您不能直接使用它们unloadbeforeunload-它们在关闭窗口之间没有区别,请尝试这样做,因为它可以根据您的要求工作.

But you have to track when it is refresh or close.. both means same to beforeunload.. you can't use directly use them either unload or beforeunload- they do not differ between window close, Try this may be it will work according to your requirements.

http://docs.jquery.com/Events/unload#fn

jQuery:

$(window).unload( function () { alert("Bye now!"); } );

or javascript:

window.onunload = function(){alert("Bye now!");}

有关更多信息,请遵循以下步骤: https://developer.mozilla.org/en/DOM/window.onclose

For more information follow this: https://developer.mozilla.org/en/DOM/window.onclose

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
    function confirmBeforeUnload(e) {
        var e = e || window.event;

        // For IE and Firefox
        if (e) {
            e.returnValue = 'Any string';
        }

        // For Safari
        return 'Any string';

    }
    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;
    </script>
    <title>Untitled Document</title>
    </head>

    <body>
    </body>
    </html>

以模态方式打开调查内容以进行交互...单击以下链接可以在页面上创建模态弹出式窗口.

open survey content in modal for interaction... follow these links to create modal popup on your page ..

http://choosedaily.com/1178/15 -jquery-popup-modal-dialog-plugins-tutorials/

http://www.queness.com/post/77/simple-jquery-modal-window-tutorial -按照逐步教程进行操作,并使用代码创建模式弹出窗口.

http://www.queness.com/post/77/simple-jquery-modal-window-tutorial -- follow this step by step tutorial with code to create modal popup..

这篇关于离开页面时如何使用Jquery显示弹出式问卷调查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆