繁体   English   中英

如何允许我的 Product1 用户从 Product1 网页为我的 Product2 链接添加书签?

[英]How to allow my Product1 users to bookmark my Product2 link from Product1 web page?

我试图让我的用户通过单击按钮来为我的外部产品链接添加书签,但是 window.sidebar.addPanel 和 window.external.AddFavorite 出现问题,因为现在两者都不支持。

我有一个 PHP 应用程序并在这里寻找最合适的解决方案。

我收到“Uncaught TypeError: window.sidebar.addPanel is not a function”错误,代码如下。

<head>
    <script type="text/javascript">
        function AddToBookmark () {
            if (window.sidebar) {        // Firefox
                window.sidebar.addPanel ('Dottoro help page', 'http://help.dottoro.com', '');
            } 
            else {
                if (window.external && ('AddFavorite' in window.external)) {
                        // Internet Explorer
                    window.external.AddFavorite ('http://help.dottoro.com', 'Dottoro help page');
                }
                else {  // Opera, Google Chrome and Safari
                    alert ("Your browser doesn't support this example!");
                } 
            }
        }
   </script>
</head>
<body>
    <button onclick="AddToBookmark();">Add to Bookmark</button>
</body>

根据这个答案

addPanel已从 Firefox 版本 23 中删除。但您可以使用标记代替:

 <a href="http://stackoverflow.com" title="Stack Overflow" rel="sidebar">Bookmark me</a>

因此,您可以在AddToBookmark()函数中模拟对类似<a>标签的点击,如下所示。

const anchorTag = document.createElement('a');
anchorTag.href = "http://help.dottoro.com"
anchorTag.title= "Dottoro help page";
anchorTag.rel= "sidebar";
anchorTag.click();

 <body> <button onclick="AddToBookmark();">Add to Bookmark</button> <script type="text/javascript"> function AddToBookmark() { if (window.sidebar) { // Firefox const anchorTag = document.createElement('a'); anchorTag.href = "http://help.dottoro.com" anchorTag.title = "Dottoro help page"; anchorTag.rel = "sidebar"; anchorTag.click(); } else { if (window.external && ('AddFavorite' in window.external)) { // Internet Explorer window.external.AddFavorite('http://help.dottoro.com', 'Dottoro help page'); } else { // Opera, Google Chrome and Safari alert("Your browser doesn't support this example!"); } } } </script> </body>

暂无
暂无

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

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