1、简单的删除cookie
//删除cookiefunction deleteCookie(name){
var date=new Date()
date.setTime(date.getTime()-10000)
document.cookie=name+"=v expires="+date.toGMTString()
}
2、设置访问路径的cookie删除
/*** js 删除 http cookie
* @param name 名字
* @param path 路径
* @param domain 域名
*/
function deleteCookie(name,path,domain){
if(getCookie(name)) document.cookie= name+'='+
((path)?'path='+path:'')+
((domain)?'domain='+domain:'') +
'expires=Thu,01-Jan-1970 00:00:01 GMT'
}
/**
* js取得http cookie
* @param name cookie名字
*/
function getCookie(name) {
var start = document.cookie.indexOf( name + "=")
var len = start + name.length + 1
if((!start)&&(name!=document.cookie.substring(0,name.length))){
return null
}
if ( start == -1 ) return null
var end = document.cookie.indexOf( '', len )
if ( end == -1 ) end = document.cookie.length
return unescape( document.cookie.substring( len, end ) )
}
window.close()
<script language="javascript" type="text/javascript">//关闭所有窗口就是关闭浏览器
function closeWindow()
{
var ua=navigator.userAgent
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
if(ie)
{
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf("",ua.indexOf("MSIE "))))
if(IEversion< 5.5)
{
var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
str += '<param name="Command" value="Close"></object>'
document.body.insertAdjacentHTML("beforeEnd", str)
document.all.noTipClose.Click()
}
else
{
parent.window.opener =null
parent.window.open('','_self','')//for IE7
parent.window.close()
}
}
else
{
parent.window.close()
}
}
//清楚所有cookie
function clearCookie(){
var keys=document.cookie.match(/[^ =]+(?=\=)/g)
if (keys) {
for (var i = keys.length i--)
document.cookie=keys[i]+'=0expires=' + new Date( 0).toUTCString()
}
}
</script>
<input type="button" value="Close the Window" onclick="closeWindow()" />