add bookmark for ie & ff & opera | 影の域

影の域

关注web前端,追逐html5脚步,体会code人生

add bookmark for ie & ff & opera

| 4,086 点击

<script type="text/javascript">
var address = function (obj, url, title) {
var e = window.event || arguments.callee.caller.arguments[0];
var B = {
IE : /MSIE/.test(window.navigator.userAgent) && !window.opera,
FF : /Firefox/.test(window.navigator.userAgent),
OP : !!window.opera
};

obj.onmousedown = null;

if (B.IE) {
obj.attachEvent("onmouseup", function () {
try {
window.external.AddFavorite(url, title);
window.event.returnValue = false;
} catch (exp) {
}
});
}
else {
if (B.FF || obj.nodeName.toLowerCase() == "a") {
obj.setAttribute("rel", "sidebar"),
obj.title = title,
obj.href = url;
}
else if (B.OP) {
var a = document.createElement("a");
a.rel = "sidebar",
a.title = title,
a.href = url;
obj.parentNode.insertBefore(a, obj);
a.appendChild(obj);
a = null;
}
}
};
</script>

<a href="javascript:void(0);" onmousedown="address(this, 'http://baidu.com', '百度首页')">添加百度到收藏</a>