Giter Site home page Giter Site logo

view-history's Introduction

View History

管理网页浏览历史记录,保存页面浏览记录,取出的记录内容进行数组化处理。IE6 和 IE7 需要第三方 JSON 库支持,推荐使用 json2.js

文章浏览历史记录

相关文章和 DEMO

Parameters

  • limit {number}

    保存数量,默认为 10。当该值为 0 时,无限保存。

  • storeagekey {string}

    该工具使用 localStorage 保存信息,这是对应使用的 localStorage key。

  • primaryKey {string}

    唯一属性,当指定属性相同,老的内容将替换成新的内容。默认为 url,因为页面 URL 通常不会重复。

Usage

引用 JavaScript 和初始化

<script src="view-history.js"></script>
<script>
if(typeof localStorage !== 'undefined' && typeof JSON !== 'undefined') {
	var viewHistory = new ViewHistory();
	viewHistory.init({
		limit: 5,
		storeagekey: 'viewHistory',
		primaryKey: 'url'
	});
}
</script>

保存页面信息

<script>
/* <![CDATA[ */
// 如果 ViewHistory 的实例存在,则可以将页面信息写入。
if(viewHistory) {
	var page = {
		"title": document.getElementsByTagName('title')[0].innerHTML,
		"url": location.href // 这是 primaryKey
		// "time": new Date()
		// "author": ...
		// 这里可以写入更多相关内容作为浏览记录中的信息
	};
	viewHistory.addHistory(page);
}
/* ]]> */
</script>

获取和显示浏览历史信息

<script>
/* <![CDATA[ */
var wrap = document.getElementById('view-history');

// 如果 ViewHistory 的实例存在,并且外层节点存在,则可显示历史浏览记录
if(viewHistory && wrap) {
	// 获取浏览记录
	var histories = viewHistory.getHistories();

	// 组装列表
	var list = document.createElement('ul');
	if(histories && histories.length > 0) {
		for(var i=histories.length-1; i>=0; i--) {
			var history = histories[i];

			var item = document.createElement('li');
			var link = document.createElement('a');
			link.href = history.url;
			link.innerHTML = history.title;

			item.appendChild(link);
			list.appendChild(item);
		}

		// 插入页面特定位置
		wrap.appendChild(list);
	}
}
/* ]]> */
</script>

License

View History is released under the MIT license:

Copyright (c) 2007-2013 NeoEase.com.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

view-history's People

Contributors

wuzhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.