PDA

View Full Version : Bookmark Site Script not working in Opera



jesusarmy
12-11-2008, 11:58 AM
Script Title: Bookmark Site

URL: http://www.dynamicdrive.com/dynamicindex9/addbook.htm

The current release of Opera will not add a bookmark from this script. I understand that this issue applies to Opera 7+ which blocks programmed clicks.

The workaround is to write the links in Javascript, and write one for Opera with embedded links to create the bookmark:


<script type="text/javascript">
var sidebarurl = "http://www.jesus.org.uk/sidebar.htm"; // Change as required
var sidebartitle = "Jesus Army pages"; // Change as required
var url = this.location;
var title = document.title;

function bookmarksite() {
if (window.sidebar && window.sidebar.addPanel){ // Firefox
window.sidebar.addPanel(sidebartitle, sidebarurl,"");
}
else if ( document.all ) { // IE Favorite
window.external.AddFavorite(url, title);
}
else if (window.opera && window.print) {
// do nothing
}
else if (navigator.appName=="Netscape") {
alert("Please click OK, then press <Ctrl-D> to bookmark this page.");
}
}

if (window.sidebar && window.sidebar.addPanel) {
document.write('<a href = "javascript:bookmarksite();">Bookmark Site</a>');
}
else if (document.all) {
document.write('<a href = "javascript:bookmarksite();">Add to Favourites</a>');
}
else if (window.opera && window.print) {
document.write('<a href = "'+sidebarurl+'" title="'+sidebartitle+'" rel="sidebar">Bookmark Site</a>');
}
else if (navigator.appName=="Netscape") {
document.write('<a href = "javascript:bookmarksite();">Bookmark this page</a>');
}
</script>

This script can just be put in the body of the page where the bookmark link is required.

Opera and Firefox put a bookmark in the sidepanel. For this the best idea is a specific mini page that gives a selection of links for your site, and which has a line <base target=_content> in the head section of the page so that clicks on the mini page will open in the main page of the browser

jesusarmy
12-11-2008, 04:42 PM
There may be some difficulty getting this to work inside a frameset. This version overcomes that problem. As before, any apostrophes in the title need to be escaped with backslashes.


<script type="text/javascript">
sidebarurl = "http://www.jesus.org.uk/sidebar.htm"; // Change as required
sidebartitle = "Jesus Army pages"; // Change as required

if (window.sidebar && window.sidebar.addPanel) {
document.write('<a href = "#" onClick="window.sidebar.addPanel(\''+sidebartitle+'\', \''+sidebarurl+'\',\'\');return false;">Bookmark Site</a>');
}

else if (document.all) {
document.write('<a href = "#" onClick="window.external.AddFavorite(location.href, document.title);return false;">Add to Favorites</a>');
}

else if (window.opera && window.print) {
document.write('<a href = "'+sidebarurl+'" title="'+sidebartitle+'" rel="sidebar">Bookmark Site</a>');
}

else if (navigator.appName=="Netscape") {
document.write('<a href = "#" onClick="alert(\'Please click OK, then press <Ctrl-D> to bookmark this page.\');return false;">Bookmark this page</a>');
}
</script>
Google Chrome seems to think it is a Netscape browser in this code, and works OK.