简体   繁体   English

在IE6 +,FF和Safari的JavaScript中添加到收藏夹

[英]Add to favorites in JavaScript for IE6+, FF and Safari

I tried some "add to favorties" JavaScript scripts.. With IE8, I get an "access denied" (is that even possible to add a bookmark via JS with IE8?) and it just doesn't work with IE6... Anybody has a good script that works on most browsers? 我尝试了一些“添加到收藏夹”的JavaScript脚本。使用IE8,我收到了“访问被拒绝”(甚至可能通过IE8通过JS添加书签吗?),但它根本无法与IE6一起使用...有一个适用于大多数浏览器的好的脚本?

Thanks! 谢谢!

Both IE6 and IE8 will need the users to press CTRL+D to add the website to the favourites. IE6和IE8都需要用户按CTRL + D才能将网站添加到收藏夹中。

Edit: Sorry, I run into a brain malfunction and mixed some words out. 编辑:对不起,我遇到了脑部故障,并把一些话混了出来。

Actually, IE8 allows javascript to manage the favourites. 实际上,IE8允许javascript管理收藏夹。

To be more precise, and if you use jquery on your website, here's an example : 更准确地说,如果您在网站上使用jquery,请参见以下示例:

    $("a.bookmark").click(function(e) {
            if ($.browser.opera == false) {
                e.preventDefault();
                var url = this.href;  
                var title = this.title;

                if ($.browser.mozilla == true) {
                    window.sidebar.addPanel(title, url, '');
                    return false;
                } else if($.browser.msie == true) {  
                    window.external.AddFavorite( url, title);
                    return false;
                } else {
                    alert('Please use CTRL + D to bookmark this website.');
                }


    }
});

Note: the "a.bookmark" is required to work with opera, since it recognizes .bookmark class in anchor tags and executes the bookmark funcion on click. 注意:“ a.bookmark”必须与Opera配合使用,因为它可以识别锚标记中的.bookmark类并在单击时执行书签功能。

It supports IE7 & 8, Firefox 2 & 3, and Opera 9 (at least) .. Safari isn't supported, and IE6 I couldn't test it here, sorry. 它支持IE7和8,Firefox 2和3以及Opera 9(至少)..不支持Safari,IE6在这里我无法对其进行测试,对不起。

I have a client who wants this. 我有一个想要这个的客户。 So far as tested this is a totally 100% cross platform solution. 到目前为止,这是一个完全100%的跨平台解决方案。 Not only does it give the standard bookmarking functionality, but it educates your user at the same time :) :) :) 它不仅提供标准的书签功能,而且还可以同时教育您的用户:) :) :)

I've tested it as working on Chrome, Firefox and IE. 我已经在Chrome,Firefox和IE上对其进行了测试。

Code is below: 代码如下:

<a class="button" onClick="alert('Hold down Ctrl and D at the same time to add this to your favourites')">Bookmark</a>

.. now the real question is whether to use confirm or alert. ..现在真正的问题是使用确认还是警报。 Confirm may give the users a reassuring but false sense of control about whether they added the bookmark or not? 确认可能会使用户对他们是否添加书签有一种放心但错误的控制感?

This solution looks solid. 该解决方案看起来很可靠。 But I'd recommend that you test it across whatever browsers you plan to support. 但我建议您在计划支持的所有浏览器中对其进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM