使用 JavaScript 添加浏览器书签
我有一个 ASP.NET 网页,其中有一个按钮。单击该按钮,书签应保存在浏览器中,当用户单击书签时,应浏览到 http://google.com 。
我如何确保它适用于几乎所有标准浏览器或至少适用于 IE、Mozilla Firefox、Opera 和 Google Chrome。
另一种情况,我也以同样的方式创建第二个书签。但是当用户单击第二个书签时,它应该运行一段 JavaScript 代码。
I have an ASP.NET web page having a button in it. Clicking the button, a bookmark should be saved in the browser and when the user clicks the bookmark, it should surf to http://google.com.
How do I make sure that it works with almost all the standard browsers or at least with IE, Mozilla Firefox, Opera and Google Chrome.
Another case, I create a 2nd bookmark also in the same way. But when the user clicks upon the 2nd bookmark, it should run a piece of JavaScript code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我编写的这段代码适用于 IE、Firefox 和 Opera(不幸的是它不适用于 Google Chrome)。
I wrote this piece of code which works for IE, Firefox and Opera (unfortunately it doesn't work for Google Chrome).
出于安全原因无法完成。过去可以使用专有的 IE 命令,但我认为这在 IE 7 中就结束了。在其他版本中绝对不可能。
Mozilla Developer Central 上的相关讨论
Can't be done for security reasons. It used to be possible using a proprietary IE command but I think that ended in IE 7. Definitely impossible in the others.
Related discussion on Mozilla Developer Central
据我所知,Firefox 目前没有添加常规书签的功能。 Firefox 中只能创建侧边栏书签。
您可以在这里找到适用于大多数浏览器的脚本: http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html
正如您在这一行中看到的:
它只为 Firefox 添加了一个侧边栏条目,这对用户来说不太友好。
In Firefox as far as I know there is currently no function that adds a regular bookmark. Only a sidebar bookmark can be created in Firefox.
Here you can find a script that works for most browsers: http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html
As you can see at this line:
it only adds a sidebar entry for Firefox, which is not very user friendly.
对于FireFox,不需要为书签设置任何javascript,只有带有 title 和 rel="sidebar" 的锚标记可以执行此功能
我已经在 FF9 上测试过
For FireFox no need to set any javascript for the bookmark, only an anchor tag with title and rel="sidebar" can do this functionality
I have tested it on FF9