Add to Bookmark / Favorites on Drupal

Tested on:

  • Drupal 5.x
  • Zen theme

On your page.tpl.php, change default node links rendering with this:

<?php if ($links): ?>
<div class=”links”>
<?php
# add to favorites / bookmarks link
$node->links[‘add2fav’] = Array(
‘title’=>trim(t(“Add to favorites”)),
‘href’=>$_GET[‘q’],
‘attributes’=>Array(
‘class’=>”add2fav”,
‘onclick’=>’bookmark()’,
)
);
# intercept and theme node links
print theme_links($node->links);
print ‘<script type=”text/javascript”>// <![CDATA[
function bookmark(){
var url = window.document.location;
var title = window.document.title;
if ((navigator.appName == “Microsoft Internet Explorer”) && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite(url,title);
} else if (navigator.appName == “Netscape”) {
window.sidebar.addPanel(title,url,””);
} else {
alert(“Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark”);
}
}
// ]]></script>’;
?>
</div>
<?php endif; ?>

Now any node has your “Add to favorites” link, try to click it.

If you wrap alert message in a t() function, you can also translate displayed message.

See also:

Advertisements

3 thoughts on “Add to Bookmark / Favorites on Drupal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s