Forums / Setup & design / Add to Favourites

Add to Favourites

Author Message

Adam Menary

Thursday 14 June 2007 7:51:01 pm

Is there some way to have an add to favourites link in say an article so that it adds the current page to the web browsers fafourites list?

Joe Kepley

Friday 15 June 2007 10:55:17 am

Here's some javascript that we've used to do this:

A function to support adding bookmarks - you can put this in your header or an included file:

// Released under GNU/GPL License - http://www.gnu.org/copyleft/gpl.htm
// copyright (C) 2005 by Michael Carico - All rights reserved
// website http://www.kabam.net

function displayLink(p_type, p_url, p_title, p_link_text) {
    var agt = navigator.userAgent.toLowerCase();
    var p_here = top.location.href;
    if (p_type == 3) {
        if (agt.indexOf("opera") != -1) {
            document.write("<a href=\"" + p_here + "\" title=\"" + p_title + "\" rel=\"sidebar\">" + p_link_text + "</a>");
        } else {
            document.write("<a href=\"javascript:addBookmark('" + p_title + "',top.location.href);\" title=\"" + p_title + "\" >" + p_link_text + "</a>");
        }
    } else {
        if (agt.indexOf("opera") != -1) {
            document.write("<a href=\"" + p_url + "\" title=\"" + p_title + "\" rel=\"sidebar\">" + p_link_text + "</a>");
        } else {
            document.write("<a href=\"javascript:addBookmark('" + p_title + "','" + p_url + "');\" title=\"" + p_title + "\" >" + p_link_text + "</a>");
        }
    }
}

function addBookmark(title, url) {
    var msg_netscape = "NetScape message";
    var msg_opera = "This function does not work with this version of Opera.  Please bookmark us manually.";
    var msg_other = "Your browser does not support automatic bookmarks.  Please bookmark us manually.";
    var agt = navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) {
        if (window.opera && window.print) {
            return true;
        } else {
            alert(msg_other);
        }
    } else if (agt.indexOf("firefox") != -1) {
        window.sidebar.addPanel(title, url, "");
    } else if (agt.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4) {
        window.external.AddFavorite(url, title);
    } else if (agt.indexOf("netscape") != -1) {
        window.sidebar.addPanel(title, url, "");
    } else if (window.sidebar && window.sidebar.addPanel) {
        window.sidebar.addPanel(title, url, "");
    } else {
        alert(msg_other);
    }
}

(Originally from a mambo module)

Then, to create the link (in your article, or template, or elsewhere):

<script language="JavaScript">displayLink('','http://www.example.com','Example Site','Bookmark this page')</script>

eZ debug

Timing: Jan 20 2025 06:47:20
Script start
Timing: Jan 20 2025 06:47:20
Module start 'content'
Timing: Jan 20 2025 06:47:20
Module end 'content'
Timing: Jan 20 2025 06:47:20
Script end

Main resources:

Total runtime0.0167 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 588.8516180.8438
Module start 'content' 0.00610.0054 769.695393.7578
Module end 'content' 0.01150.0052 863.453170.7031
Script end 0.0167  934.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002313.8932120.0002
Check MTime0.00116.3353120.0001
Mysql Total
Database connection0.00063.613510.0006
Mysqli_queries0.002816.662140.0007
Looping result0.00000.089920.0000
Template Total0.004828.810.0048
Template load0.00095.199810.0009
Template processing0.003923.599510.0039
Override
Cache load0.00063.727610.0006
General
dbfile0.00063.4152100.0001
String conversion0.00000.041430.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs