抛弃cookie使用浏览器本地存储实现浏览记录。 1,首先下载localforage.min.js这个组件,而后在引入进来(如果浏览器不支持indexdb,会自动用localStorage保存)localStorage保存一般为5m,而indexdb本地数据库支持上GB的存储。 2,以浏览文章为例,首先得在公用JS文件写入INDEXdb大数据库配置 [ol]localforage.config({driver: localforage.INDEXEDDB, // 使用 IndexedDBname: 'meiwenyyuqi', // 数据库名称version: 1.0, // 数据库版本storeName: 'meiweny' // 存储对象的名称});[/ol]复制代码[ol]//保存阅读记录function set_history(_url, _name, _id) {var yueduhistorytime = new Date().formatCode();var userpic = $('.userinfos .userface').attr('src');/var username = $('.userinfos .username').text();var user = {id: _id,name: _name,url: _url,yueduhistorytime: yueduhistorytime,username:username,userpic: userpic,};localforage.getItem('yuedu_news_History').then(function(Game_Data) {Game_Data = Game_Data || [];var userExists = Game_Data.some(function(item) {return item.name === _name;});if (!userExists) {Game_Data.push(user);localforage.setItem('yuedu_news_History', Game_Data).then(function() {localStorage.setItem('duanpian_history_Length', Game_Data.length);}).catch(function(err) {console.error("Error setting item", err);});} else {console.log("User already exists");}}).catch(function(err) {console.error("Error getting item", err);});}[/ol]复制代码[ol]//获取阅读记录function get_history(limit = 10) {return localforage.getItem('yuedu_news_History').then(function(Game_Data) {Game_Data = Game_Data || [];var yueduHistory = Game_Data.slice().reverse();/var topRecords = yueduHistory.slice(0, limit);var aaastr = '';topRecords.forEach(function(item) {aaastr += '[url=]' + item.name + '[/url]' + yuedu_riq + '';});return aaastr;}).catch(function(err) {console.error("Error getting item", err);return ''; });}[/ol]复制代码 浏览器, 数据库