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>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 10:21:29
Script start
Timing: Jan 18 2025 10:21:30
Module start 'layout'
Timing: Jan 18 2025 10:21:30
Module start 'content'
Timing: Jan 18 2025 10:21:30
Module end 'content'
Timing: Jan 18 2025 10:21:30
Script end

Main resources:

Total runtime0.6643 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 588.9453152.6094
Module start 'layout' 0.00630.0035 741.554739.4141
Module start 'content' 0.00980.6529 780.9688462.6797
Module end 'content' 0.66270.0016 1,243.648412.3438
Script end 0.6643  1,255.9922 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.5312160.0002
Check MTime0.00150.2183160.0001
Mysql Total
Database connection0.00100.156410.0010
Mysqli_queries0.621193.4967540.0115
Looping result0.00050.0724520.0000
Template Total0.630094.820.3150
Template load0.00230.351920.0012
Template processing0.627794.483520.3138
Template load and register function0.00040.061110.0004
states
state_id_array0.00130.198710.0013
state_identifier_array0.00090.133520.0004
Override
Cache load0.00190.2890110.0002
Sytem overhead
Fetch class attribute can translate value0.00100.151720.0005
Fetch class attribute name0.00200.301420.0010
XML
Image XML parsing0.00030.041520.0001
class_abstraction
Instantiating content class attribute0.00000.001120.0000
General
dbfile0.00160.2399100.0002
String conversion0.00000.001440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 9
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs