欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

js加入收藏夹代码(兼容ie/ff/op)_javascript技巧

程序员文章站 2022-05-10 23:46:02
...
复制代码 代码如下:

var www_jb51_net = 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;
}
}
};
收藏脚本之家
相关标签: js 加入收藏