0

I am using cookies, Like...

HttpCookie id = new HttpCookie("id");
id.Value = "2"
Response.Cookies.Add(id);

and i am using this cookies in a table

unique    cookies    productid
1          2          1
2          2          3
3          2          4
4          1          1
5          1          2
6          2          1

Now i want to process on browser close the data stored in the table having cookies value 2 in column(cookies) get deleted.

I mean after close of my browser tag

my table should be seen as

unique    cookies    productid
4          1          1
5          1          2

please help me

4

1 回答 1

0

这可能会奏效。使用 Javascript/Jquery 查看浏览器是否正在关闭

<script type="text/javascript">
$(function () {
    $(window).unload(function () {
        //run ajax webmethod call here
    });
});
</script>

如果上述方法不起作用,请在body

<body onbeforeunload="CloseFunction();">

然后创建一个名为CloseFunction并在那里运行 ajax webmethod 的方法:

function CloseFunction()
{
//run ajax webmethod call here
}

请参阅此链接以了解如何进行 ajax webmethod 调用

于 2013-07-17T13:27:28.947 回答