sessionstorage

前端面试那些坑之HTML篇

允我心安 提交于 2019-11-27 08:09:41
HTML 1、Doctype作用?标准模式与兼容模式各有什么区别? (1)、<!DOCTYPE>声明位于位于HTML文档中的第一行,处于<html> 标签之前。告知浏览器的解析器用什么文档标准解析这个文档。DOCTYPE不存在或格式不正确会导致文档以兼容模式呈现。 (2)、标准模式的排版和JS运作模式都是以该浏览器支持的最高标准运行。在兼容模式中,页面以宽松的向后兼容的方式显示,模拟老式浏览器的行为以防止站点无法工作。 2、HTML5为什么只需要写<!DOCTYPE HTML>? HTML5 不基于 SGML,因此不需要对DTD进行引用,但是需要doctype来规范浏览器的行为(让浏览器按照它们应该的方式来运行);而HTML4.01基于SGML,所以需要对DTD进行引用,才能告知浏览器文档所使用的文档类型。 3、行内元素有哪些?块级元素有哪些?空(void)元素有那些? 首先:CSS规范规定,每个元素都有display属性,确定该元素的类型,每个元素都有默认的display值,如div的display默认值为“block”,则为“块级”元素;span默认display属性值为“inline”,是“行内”元素。 (1)行内元素有:ab span img input select strong(强调的语气) (2)块级元素有:divul ol li dl dt dd h1 h2 h3

cookie和session,sessionStorage、localStorage和cookie的区别

萝らか妹 提交于 2019-11-27 03:23:09
1.cookie   含义: 存储在访问者的计算机中的变量,即存储在客户端   创建一个cookie     /* getCookie方法判断document.cookie对象中是否存有cookie,若有则判断该cookie中是否含有指定c_name的cookie,有则返回数据 没有则返回空串 */  function getCookie(c_name){       if (document.cookie.length>0){         c_start=document.cookie.indexOf(c_name + "=")   // indexOf() 返回指定字符串值在某个字符串中首次出现的位置,如果没有出现则返回-1         if (c_start!=-1){           c_start=c_start + c_name.length+1        // 0 + 8 + 1 即username= 之后的位置 9           c_end=document.cookie.indexOf(";",c_start)           if (c_end==-1) c_end=document.cookie.length           return unescape(document.cookie.substring(c_start,c

前端如何写登录页面

元气小坏坏 提交于 2019-11-27 03:13:10
登录页面的主要思路有很多,这里提供两个先 第一是我目前项目里面老人写的,逻辑是在每次请求时先对后端返回的状态码做判断,如果是无权限或者失效状态,那就使用window.location.href来跳转到登录页面,但是有个问题,就是页面渲染的顺序问题,主页会先渲染然后到请求时才会判断请求结果,这个有延迟,login弹出不是先弹出,会先看到主页。这里要看你的项目是否接受这个问题。 第二个就是利用路由钩子router.beforeEach()参数有to from next来做,先进入login,在进入之前查sessionStorage或者本地的cookie或者localStorage里面的登录状态(这个是之前登录放在本地的,可能包括用户名和密码和有效期)。如果不需要登录,那就让进入login的router的next里面写入主页的path,这样就是在函数执行完后中断当前路由直接进入next里面的path。这样就进到主页了。如果是没有的话,或者过期了,那么就进入login页面发起axios请求,来创建登录状态了,要用sessionStorage还是localStorage还是cookie,什么时候删除本地的登录状态码,就要看项目了,注意最好是手动删除一下。这里的连接用了sessionstorage来做的,这里要把它为空的状态判断到。 https://www.jianshu.com/p

cookie session sessionStorage localStorage

不打扰是莪最后的温柔 提交于 2019-11-26 17:28:21
什么是会话?   会话指的是浏览器与服务器之间的数据交互。所白了就是 浏览器和服务器进行的请求和响应。   http协议是无状态的,多次请求之间没有关联性    cookie和session的作用?干啥的?   利用cookie和session可以进行 会话保持 , 会话保持就是指: 保持用户的登录状态 ,服务器记录了用户的登录信息,下一次访问服务器就认识该用户了 关于cookie      cookie是浏览器中储存数据的容器,大小为 4k     cookie中的数据会在请求时,进行携带     cookie默认是会话级别的,一旦关闭浏览器cookie就会被销毁     cookie里面可以存储sessionid      常见的一些面试问题  1 cookie是浏览器中存储数据的容器,为什么服务器中可以获取cookie中的数据?      因为cookie在向服务器请求时,会将cookie中的数据 携带在请求头中 ;服务器可以读取请求头中的内容,从而间接的获取cookie中的数据。(cookie中的数据被放在请求头中,发送到服务器) 2 cookie是浏览器中存储数据的容器,为什么服务器可以设置cookie中的数据?      服务器是无法直接修改cookie的,但是可以通过响应头来设置;setcookie设置的是响应头;set-cookie:'值'

Scope of sessionStorage and localStorage

Deadly 提交于 2019-11-26 17:21:20
I read some documentation on sessionStorage and localStorage, but I don't understand what the scope is: the domain, a specific page? For example, if I have the following pages: http://example.com/products.aspx?productID=1 http://example.com/products.aspx?productID=2 http://example.com/services.aspx?serviceID=3 And if on each of the above pages I run (with idvalue being the value in the querystring): localStorage.setItem('ID',idvalue); Am I going to end up with 3 different values stored, or are the values going to overwrite each other? Rob W The values are going to overwrite each other. Each

Where the sessionStorage and localStorage stored?

情到浓时终转凉″ 提交于 2019-11-26 14:25:28
Where are sessionStorage and localStorage stored on the client's computer? Could you tell me the path? NatureShade Firefox Firefox stores localstorage in webappsstore.sqlite file in the profile folder. Firefox (Windows XP): C:\Documents and Settings\<Windows login/user name>\Application Data\Mozilla\Firefox\Profiles\<profile folder>\webappsstore.sqlite Firefox (Windows Vista and above): C:\Users\<Windows login/user name>\AppData\Roaming\Mozilla\Firefox\Profiles\<profile folder>\webappsstore.sqlite or: %APPDATA%\Mozilla\Firefox\Profiles\<profile folder>\webappsstore.sqlite Firefox on linux: ~/

Scope of sessionStorage and localStorage

。_饼干妹妹 提交于 2019-11-26 04:40:31
问题 I read some documentation on sessionStorage and localStorage, but I don\'t understand what the scope is: the domain, a specific page? For example, if I have the following pages: http://example.com/products.aspx?productID=1 http://example.com/products.aspx?productID=2 http://example.com/services.aspx?serviceID=3 And if on each of the above pages I run (with idvalue being the value in the querystring): localStorage.setItem(\'ID\',idvalue); Am I going to end up with 3 different values stored, or

Where the sessionStorage and localStorage stored?

牧云@^-^@ 提交于 2019-11-26 03:54:27
问题 Where are sessionStorage and localStorage stored on the client\'s computer? Could you tell me the path? 回答1: Firefox Firefox stores localstorage in webappsstore.sqlite file in the profile folder. Firefox (Windows XP): C:\Documents and Settings\<Windows login/user name>\Application Data\Mozilla\Firefox\Profiles\<profile folder>\webappsstore.sqlite Firefox (Windows Vista and above): C:\Users\<Windows login/user name>\AppData\Roaming\Mozilla\Firefox\Profiles\<profile folder>\webappsstore.sqlite

Web缓存

∥☆過路亽.° 提交于 2019-11-25 22:29:02
一、前端缓存概述 前端缓存主要是分为 HTTP缓存 和 浏览器缓存 。 HTTP缓存是在HTTP请求传输时用到的缓存,主要在服务器代码上设置; 而浏览器缓存主要由前端开发在前端js上进行设置。 二、分类 1. HTTP缓存 HTTP缓存都是从第二次请求开始的。第一次请求资源时,服务器返回资源,并在respone header头中回传资源的缓存参数;第二次请求时, 浏览器判断这些请求参数,击中强缓存就直接200,否则就把请求参数加到request header头中传给服务器,看是否击中协商缓存,击中返回304,否则服务器会返回新的资源。 1.1 强缓存 可选值 优先级 优缺点 Pragma no-cache:不能直接使用缓存,开始服务器新鲜度判定 中 已被废弃 Cache-Control max-age:xx秒:相对时间,强缓存必备 no-cache:不直接使用缓存,开始服务器新鲜度判定 no-store:每次都下载最新资源 public/private: 是否只能被单个用户保存 高 无 Expires GMT时间 低 服务器和本地的时间不一定统一 1.2 协商缓存 协商缓存都是成对出现的 可选值 优先级 优缺点 Last-Modify/if-Modify-Since GMT时间 依次比较,排序靠后 1.修改并不意味着改变 2.秒级判断 ETag/if-None-Match 校验值