开发者

Chrome not supporting my javascript

I just want, when a user comes to my site and closes the window, then I want to know the reason for leaving from my site.

So I'm sending the user to a survey page, using the following script.

It works in every browser but not in Chrome

<script type="text/javascript">

window.onbeforeunload = confirmExit;

function c开发者_运维百科onfirmExit() {
    if (location.href.indexOf("index.php") != -1)
    {
        location.href = "http://www.test.com/survey.php";
        return "Press 'cancel to go 'survey'";
    }
}

</script>


Have you tried to use window.location = ("http://www.test.com/survey.php"); or window.open ("http://www.test.com/survey.php"); instead? That may be easier to do.

You can also do window.open ("http://www.test.com/survey.php", '_newtab'); This will make users less upset off when they are forced to redirect after leaving, because it will be in a new tab.


Well, sometimes there is a good reason for such a code user310850 is quoting

  1. not all websites are in Web, some of them are internal corporate websites

  2. Some if not most of big companies still use IE 6 as standard browser

I would use unload event handler. I assume jquery is good

$(window).unload(function() {
  //your code here
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜