zoukankan      html  css  js  c++  java
  • cookie

    cookie的重要字段

    [name][value][domain][path][expires][httponly][secure]

    domain默认是本域;

    path默认是目标界面的路径。例如guiqing.com/admin/login.html页面通过javascript来设置一个cookie,那么path值就是/admin/。那么guiqing/other/index.html的界面就无法获得

    guiqing.com/admin/login.html设置的cookie了,除非用iframe

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>cookieb</title>
    </head>
    <body>
    	<button type="button" onclick="setCookie()">设置cookie</button>
    	<button type="button" onclick="setCookie1()">设置cookie</button>
    	<button type="button" onclick="getCookie()">获取cookie</button>
    	<script>
    		window.onload = function(){
    			var iframeEle = document.createElement("iframe");
    			iframeEle.src = "http://127.0.0.1:8080/cookie1/a.html";
    
    			document.getElementsByTagName('body')[0].appendChild(iframeEle);
    			iframeEle.onload = function(){
    				var childDom = iframeEle.contentDocument || iframeEle.contentWindow.document;
    				alert(childDom.cookie);
    			}
    		}
    		function setCookie(){
    			document.cookie="guiqing=cookieB";
    		}
    		function setCookie1(){
    			document.cookie="guiqing=cookieB1";
    		}
    		function getCookie(){
    			var guiqing = document.cookie;
    			alert(guiqing);
    		}
    	</script>
    </body>
    </html>
    

    httpOnly是指仅在HTTP层面上传输的cookie,客户端脚本就无法读写该cookie了

    secure指的是设置了secure标志的cookie仅在HTTPS层面上安全传输,如果是http的,就不会带上这个cookie。

    本地cookie和内存cookie

    内存cookie在浏览器关掉后就没了

    本地存储主要包括: 本地cookie,localStorage,Flash Cookie

  • 相关阅读:
    导航条按钮的设置UIBarButtonItem
    动态修改app build版本CFBundleVersion
    iOS应用图片尺寸制作脚本
    iPad所有平板型号屏幕尺寸
    一个小时学会Git
    NSLog的各种打印格式符和打印CGRect相关结构体
    Linux上统计文件夹下文件个数以及目录个数
    Privacy Description
    iOS开发微信支付的介绍与实现
    iOS开发苹果内购的介绍与实现
  • 原文地址:https://www.cnblogs.com/luguiqing/p/8035706.html
Copyright © 2011-2022 走看看