Skip to Content
JavaScript 经典实例:第三版
book

JavaScript 经典实例:第三版

by Adam D. Scott, Matthew MacDonald, Shelley Powers
September 2022
Intermediate to advanced
585 pages
8h 17m
Chinese
China Electric Power Press Ltd.
Content preview from JavaScript 经典实例:第三版
380
14
14
-
2
:在第二个标签页中显示存储在 sessionStorage cookie 中的数据
在新标签页窗口中,
cookie
localStorage
的值依然存在,因为
cookie
是针对会
话的,而
sessionStorage
针对标签页窗口,不持久存储。
上述两幅截图展示了跨标签页持久存储的差别,这是
sessionStorage
cookie
间除了在
JavaScript
中存取方式不同之外的另一个重要区别。但愿上述示例和两幅
截图也表明了
sessionStorage
的潜在危害,尤其是在已经使用
cookie
的情况下。
如果网站或应用的用户习惯了跨标签页窗口持久存储的
cookie
sessionStorage
的行为会让人感到意外。除了这种行为上的差异,还有一点要注意:浏览器中删除
cookie
的菜单选项可能对
sessionStorage
没有影响,这也有可能让用户大失所望。
抛开这些问题,
sessionStorage
还是有一定用途的,如果只想在特定的标签页窗口
中存储数据,
sessionStorage
是不错的选择。
最后,请注意
sessionStorage
的实现:
sessionStorage
localStorage
(下一节
介绍)都包含在
W3C DOM
Storage
规范中。二者都是
window
对象的属性,因此
可以全局访问。而且二者都是
Storage
对象的具体实现,如果修改
Storage
原型,
sessionStorage
localStorage
受影响。
Storage.prototype.someMethod ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov
JavaScript

JavaScript

David Flanagan
JavaScript

JavaScript

T. J. Crowder

Publisher Resources

ISBN: 9787519869601