• 保证页面只能打开一次Cooike版本


       最近在做webIM,嵌入到OA系统,由于WEBIM处在独立页面,所以如果多次点击就会出现多个页面,这样在IE6下,服务器推送会认不到页面.所以有了下面的代码:

    <script language="javascript" type="text/javascript">
    window.onload = function () {
                if (GetCookie("IsOpen") == "") {
                    SetCookie("IsOpen", "1");
                    StartService();
                } else {
                    window.onunload = null;
                    window.opener = null;
                    window.open("", "_self");
                    window.close();
                }
            }

            window.onunload = function () {
                if (GetCookie("IsOpen") != "")
                    DeleteCookie("IsOpen");
            }


    function GetCookieVal(offset) {
    /// <summary>
    /// //取得项名称为offset的cookie值
    /// </summary>
    /// <param name="name">Cookie名称</param>
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
    endstr
    = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }

    function GetCookie(name) {
    /// <summary>
    /// 根据名称获得Cookie值
    /// </summary>
    /// <param name="name">Cookie名称</param>
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return GetCookieVal(j);
    i
    = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return "";
    }


    function SetCookie(name, value) {
    /// <summary>
    /// 设置Cookie
    /// </summary>
    /// <param name="name">Cookie名称</param>
    /// <param name="value">Cookie值</param>
    var argc = SetCookie.arguments.length;
    var argv = SetCookie.arguments;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;


    document.cookie
    = name + "=" + value +
    ((path
    == null) ? "" : ("; path=" + path)) +
    ((domain
    == null) ? "" : ("; domain=" + domain)) +
    ((secure
    == true) ? "; secure" : "");
    }

    function DeleteCookie(name) {
    /// <summary>
    /// 删除Cookie
    /// </summary>
    /// <param name="name">Cookie名称</param>
    var exp = new Date();
    exp.setTime(exp.getTime()
    - 1);
    var cval = GetCookie(name);
    document.cookie
    = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    </script>

    把上面的代码,放到head下面就可以了.呵呵够简单了吧?当然上面的代码主要解决的是用超链接打开的页面,如果是window.open打开的页面呢,那就更简单了,代码如下:

    var win = null;//定义一个变量去判断就可以了
    if (win == null)
    {
    win
    =window.open("Main.aspx", '', strfeatures);
    }
    版权说明

      如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
      作      者:温景良
      文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

  • 相关阅读:
    Python的内置模块itertools
    列表的sort()和sorted()方法
    Python面试
    数据分析相关概念
    数据分析中Numpy,Pandas,Matplotlib,scripy和Scikit-Learn等数据处理库...
    mysql数据库的语法及简介
    Cannot add foreign key constraint
    MySQL数据库重装
    MySQL数据库在Python中的操作
    Python中的取整函数
  • 原文地址:https://www.cnblogs.com/wenjl520/p/2037211.html
Copyright © 2020-2023  润新知