从 JavaScript 添加到浏览器收藏夹/书签但适用于所有浏览器(我的不适用于 Chrome)? [英] Add to browser favorites/bookmarks from JavaScript but for all browsers (mine doesn't work in Chrome)?

查看:67
本文介绍了从 JavaScript 添加到浏览器收藏夹/书签但适用于所有浏览器(我的不适用于 Chrome)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮忙,我正在使用以下内容向 IE 和 Firefox 添加书签,但它在 Chrome 中不起作用,我也没有收到说不支持"的错误消息..

Can anyone help, I am using the following for adding a bookmark to IE and Firefox but its not working in Chrome and I don't get my error msg saying "not supported" either..

任何人都知道支持所有浏览器的好脚本,或者至少回来告诉我它不受支持,我可以访问 jQuery - 也许有某种方法可以检测浏览器

Anybody know of a good script to support ALL browsers or at least to come back and tell me its not supported, I have access to jQuery - maybe there is some way to detect the browser

我目前正在使用它,它适用于 IE 和 Firefox,但不适用于 chrome

I am currently using this and it works for IE and Firefox but not chrome

if (window.sidebar) { // Mozilla Firefox
    window.sidebar.addPanel(name, url, "");
}
else if (window.external) { // IE
    window.external.AddFavorite(url, name);
}
else if (window.opera && window.print) {
    window.external.AddFavorite(url, name);
}
else {
    alert('not supported');
}

推荐答案

抱歉,没有跨浏览器的方式来做到这一点.您的 FF 示例也已损坏:它不会创建常规书签,而是设置要在侧边栏中打开的书签.你必须使用书签服务来创建一个实际的书签,但这'会因安全限制而失败.

Sorry, but there's no cross-browser way to do this. Your FF example is broken as well: It won't create a regular bookmark, but a bookmark set to be opened in the sidebar. You'd have to use the bookmark-service to create an actual bookmark, but this'll fail due to security restrictions.

这篇关于从 JavaScript 添加到浏览器收藏夹/书签但适用于所有浏览器(我的不适用于 Chrome)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆