简体   繁体   English

在关闭浏览器之前关闭弹出窗口的会话

[英]Kill session on popup close until the closing of browser

I want to show a popup about browser compatibility to the users visiting my website. 我想向访问我的网站的用户显示有关浏览器兼容性的弹出窗口。 I have used the popup in about 5 pages and it would be annoying for the users to see the same popup for more than once when they visit my website. 我已经在大约5页中使用了该弹出窗口,并且让用户在访问我的网站时多次看到同一弹出窗口很烦人。 So I am thinking to use a session and kill it when the user closes the poup. 所以我想在用户关闭poup时使用会话并将其终止。 IT should not be shown until the browser is restarted. 在重新启动浏览器之前,不应显示IT。 Could someone tell me how it can be done. 有人能告诉我怎么做。 I know what can be done but not how? 我知道可以做什么但不怎么做? Thanks a lot inadvance!! 非常感谢!

If you really have to do that, place a cookie that will persist during browser's lifetime. 如果您真的必须这样做,请放置一个在浏览器生命周期内保持不变的cookie。 If it doesn't exist, make one that says "A popup windows should be shown". 如果它不存在,请创建一个“应显示弹出窗口”。 After it's shown, modify that cookie using Javascript so it says "Ok, window shown, now I won't be used anymore". 显示之后,使用Javascript修改该cookie,使其显示“Ok,显示的窗口,现在我将不再使用”。

1) Definitely spend your time fixing the browser compatibility instead of learning how to control your popups. 1)绝对花时间修复浏览器兼容性,而不是学习如何控制弹出窗口。

2) Create a tiny cookie using plain javascript (or jquery wrapper) and store bc_notice=1 . 2)使用普通的javascript(或jquery包装器)创建一个小cookie并存储bc_notice=1 Then retrieve that cookie and if it's already set to 1 - don't show the popup. 然后检索该cookie,如果它已经设置为1 - 不显示弹出窗口。

<html> 
<head>
<title></title>
<script language="javascript">

function setFlag()

{

     // Call Web Service or Ajax Method with your session Key

     // CallaMethod('ScreenDisplayed');

}

</script>

</head>

<body onbeforeunload="setFlag();">

</body> 

</html>

I'm assuming by "pop-up" you mean something similar to the CNN edition selector that slides down from the top or like the SO "a new answer has been posted to this page" bar at the top of this page. 我假设通过“弹出”你的意思是类似于CNN版选择器从顶部向下滑动或类似SO“本页面顶部的新页面已发布到此页面”栏。 An actual javascript window popup would be incredibly intrusive for something like this. 一个真正的javascript窗口弹出窗口将是这样的东西令人难以置信的侵入。

Show the message once. 显示消息一次。 Once it is shown, store its status in a persistent cookie and never show it again. 显示后,将其状态存储在持久性cookie中,不再显示。 As an alternative, provide an X somewhere so the user can get rid of it and determine never to see it again. 或者,在某处提供X,以便用户摆脱它并确定永远不会再看到它。 They don't want to see it in the first place, but if you have to show it... whatever. 他们不想一开始就看到它,但是如果您必须显示它……无论如何。

Mostly - fix your issues. 主要是 - 修复你的问题。 Don't spend time worrying about fancy ways to avoid fixing them. 不要花时间担心花哨的方法来避免修复它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM