Heim  >  Artikel  >  Web-Frontend  >  js Favoritencode hinzufügen (kompatibel mit ie/ff/op)_Javascript-Kenntnisse

js Favoritencode hinzufügen (kompatibel mit ie/ff/op)_Javascript-Kenntnisse

WBOY
WBOYOriginal
2016-05-16 16:47:571328Durchsuche

复制代码 代码如下:

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;
        }
}
};
收藏脚本之家
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn