杰拉斯的博客

归档:2013年2月月

[代码收藏]设为首页和加入收藏的JavaScript代码(兼容多浏览器)

杰拉斯 杰拉斯 | 时间:2013-02-04, Mon | 6,603 views
前端开发 

其实不少非IE内核浏览器都仍不支持通过代码将网页设为主页和加入收藏的功能,因此说是兼容,其实只是一个try,catch后的提醒而已。

加入收藏:

/*
 * author : 2010-12-27 11:33:02 teresa
 * discription: add favorite
 */

function addFavorite() {
	if(document.all) {
		try {
			window.external.addFavorite(window.location.href, document.title);
		} catch(e) {
			alert("加入收藏失败,请使用Ctrl+D进行添加");
		}

	} else if(window.sidebar) {
		window.sidebar.addPanel(document.title, window.location.href, "");
	} else {
		alert("加入收藏失败,请使用Ctrl+D进行添加");
	}
}

设为首页:

/*
 * author : 2010-12-27 11:33:02 teresa
 * discription: set homepage
 */

function setHomepage() {
	if(document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(window.location.href);
	} else if(window.sidebar) {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch(e) {
				alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', window.location.href);
	} else {
		alert('您的浏览器不支持自动自动设置首页, 请使用浏览器菜单手动设置!');
	}
}

Highcharts: 非常漂亮的免费纯JavaScript图表库

杰拉斯 杰拉斯 | 时间:2013-02-01, Fri | 22,939 views
前端开发 

Highcharts是什么?

Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习、个人网站和非商业用途使用。目前HighCharts支持的图表类型有曲线图、区域图、柱状图、饼状图、散状点图和综合图表。Highcharts

HighCharts界面美观,由于使用JavaScript编写,所以不需要像Flash和Java那样需要插件才可以运行,而且运行速度快。另外HighCharts还有很好的兼容性,能够完美支持当前大多数浏览器。现在官方的最新版本为HighCharts2.3.5。

(阅读全文…)