添加到 IE6+、FF 和 Safari 的 JavaScript 收藏夹

发布于 2024-08-03 20:03:02 字数 124 浏览 2 评论 0原文

我尝试了一些“添加到收藏夹”JavaScript 脚本。使用 IE8,我收到“访问被拒绝”(甚至可以通过 JS 使用 IE8 添加书签吗?),但它不适用于 IE6... 有人有一个适用于大多数浏览器的好脚本吗?

谢谢!

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抠脚大汉 2024-08-10 20:03:02

IE6和IE8都需要用户按CTRL+D将网站添加到收藏夹。

编辑:抱歉,我脑子出了故障,混淆了一些单词。

实际上,IE8允许javascript来管理收藏夹。

更准确地说,如果您在网站上使用 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.');
                }


    }
});

注意:“a.bookmark”需要与 opera 一起使用,因为它识别锚标记中的 .bookmark 类并在单击时执行书签功能。

它支持 IE7 和8、火狐2.0 3、Opera 9(至少).. 不支持 Safari,以及 IE6 我无法在这里进行测试,抱歉。

Both IE6 and IE8 will need the users to press CTRL+D to add the website to the favourites.

Edit: Sorry, I run into a brain malfunction and mixed some words out.

Actually, IE8 allows javascript to manage the favourites.

To be more precise, and if you use jquery on your website, here's an example :

    $("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.

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.

心的憧憬 2024-08-10 20:03:02

我有一个客户想要这个。到目前为止,经过测试,这是一个完全 100% 跨平台的解决方案。它不仅提供标准的书签功能,还同时教育您的用户 :) :) :)

我已经测试了它在 Chrome、Firefox 和 IE 上的工作情况。

代码如下:

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

..现在真正的问题是是否使用确认或警报。确认可能会给用户一种放心但错误的控制感,让他们知道自己是否添加了书签?

I have a client who wants this. So far as tested this is a totally 100% cross platform solution. 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.

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?

冰之心 2024-08-10 20:03:02

这个解决方案看起来很可靠。但我建议您在您计划支持的任何浏览器上进行测试。

This solution looks solid. But I'd recommend that you test it across whatever browsers you plan to support.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文