[关闭]
@fengfeng 2015-04-25T16:36:14.000000Z 字数 3139 阅读 2033

浏览器

未分类


浏览器的本地存储

浏览器本地存储 from

IE userdata

  1. (function(window, document) {
  2. "use strict";
  3. var userData, attr, attributes;
  4. if (!window.localStorage && (userData = document.body) && userData.addBehavior) {
  5. if (userData.addBehavior("#default#userdata")) {
  6. userData.load((attr = "localStorage"));
  7. attributes = userData.XMLDocument.documentElement.attributes;
  8. window.localStorage = {
  9. "length" : attributes.length,
  10. "key" : function(idx) { return (idx >= this.length) ? null : attributes[idx].name; },
  11. "getItem" : function(key) { return userData.getAttribute(key); },
  12. "setItem" : function(key, value) {
  13. userData.setAttribute(key, value);
  14. userData.save(attr);
  15. this.length += ((userData.getAttribute(key) === null) ? 1 : 0);
  16. },
  17. "removeItem" : function(key) {
  18. if (userData.getAttribute(key) !== null) {
  19. userData.removeAttribute(key);
  20. userData.save(attr);
  21. this.length = Math.max(0, this.length - 1);
  22. }
  23. },
  24. "clear" : function() {
  25. while (this.length) { userData.removeAttribute(attributes[--this.length].name); }
  26. userData.save(attr);
  27. }
  28. };
  29. }
  30. }
  31. })(this, this.document);

Flash SharedObject

Local Storage/Session storage

web SQL/IndexedDB

application cache

浏览器协议

  1. <a href="mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body">Send email</a>
  2. <a href="tel:+468123456">Call</a>
  3. <a href="sms:+15105550101?body=hello,你好,我是宋史超"> 带中文 </a>

同源策略(Same Origin policy,SOP),

浏览器通过隔离来自不同源的文件之间的访问来提供各种安全保障。
同源策略一开始是为了管理DOM之间的访问,后来逐渐扩展到Javascript对象,但并非是全部。例如非同源的脚本之间可以调用location.assign()和location.replace()。

什么是源

把协议-域名-端口 三元素组合在一起组成“源(Origin)",不满足这一条件的被成为跨域。

原始资源 要访问的资源 非IE浏览器 IE浏览器
http://example.com/a/ http://example.com/b/ 可以访问 可以访问
http://example.com/ http://www.example.com/ 主机不匹配 主机不匹配
http://example.com/a/ https://example.com/a/ 协议不匹配 协议不匹配
http://example.com:81/ http://example.com/ 端口不匹配 可以访问

同源策略的影响

跨域解决方案

同源策略在提高了安全性,但同时也降低了灵活性。

例如很难将login.example.com与payments.example.com两个域之间的数据可以方便的传送

  1. http响应头:
  2. HTTP/1.1 200 OK
  3. Access-Control-Allow-Origin:http://another-domain.com
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注