SMOLNET PORTAL home about changes

Add to Bookmark / Favorites on Drupal

Tested on:

  • Drupal 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:


*

https://web.archive.org/web/20080423000000*/http://drupal.org/node/176913 (https://web.archive.org)
Response: 20 (Success), text/gemini
Original URLgemini://chirale.org/2008-04-23_62.gmi
Status Code20 (Success)
Content-Typetext/gemini; charset=utf-8