viviannow / autoProject

【个人】各种资料待整理
2 stars 1 forks source link

各种常见错误 #3

Open viviannow opened 8 years ago

viviannow commented 8 years ago

【iframe 访问子页面】

window.onload=function(){ var a = window.frames[0].a; console.log(a instanceof Array); console.log(a.consotructor === Array); }; 报错: Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.

原因:frame 子页面和父页面必须属于同一个域下。 解决方案:放在服务器上去访问。

viviannow commented 8 years ago

【ajax缓存问题】 一个列表也,点击加载更多。ajax加载了更多的数据,点击一个图片进入详细页,回退到列表页。 还是显示的是第一页的内容,刚才加载的第二页内容不会存储起来

?jquery.history.js ? history.pushState ?sessonStorage保存数据

viviannow commented 8 years ago

【Git bash中运行git log之后怎样终止这个命令】

q键 【git 提交不上去时】 注意看下是不是 没pull

viviannow commented 8 years ago

如何判断一个变量是数组:

【最好姿势:】 ES5提供的Array.isArray()方法,原生的才是最好的。注意,IE低版本来了,它不支持!!! var a=[1,2,3]; console.log(Array.isArray(a)); //true

【typeof: 】 数组是特殊的对象,数组的typeof结果是object,【null的typeof也是object】 console.log(typeof a ==='object & a !==null && Object.prototype.toString.call(a) !== '[object Object]');//true

【instanceof: 】 用法 a instanceof b ,a是不是b的一个实例。 var a= [1,1,1]; console.log(a instanceof Array);//true console.log(a.constructor === Array);//true 以上方法要注意嵌套frame的情况。 index.html: window.onload=function(){ var a=window.frames[0].a; console.log(a instanceof Array);//false console.log(a.constructor === Array);//false; } a.html: window.a=[1,2,3];

每个frame都有一套自己的执行环境,跨frame实例化的对象彼此不共享原型链, 打印: a instanceof window.frames[0].Array;//true;

【特性嗅探:】 不靠谱: var a = {sort : 'me'}; if(a.sort){} var a = [1,1,3]; console.log(Object.prototype.toString.call(a) === '[object Array]');//true

【就这样写】 function isArray(a){ Array.isArray?Array.isArray(a):Object.prototype.toString.call(a) === '[object Array]'; }

viviannow commented 8 years ago

【codecademy注册不成功】 显示:I'm not a robot 这个要翻墙,不然成功不了。