View Full Version : Possible to "bookmark this.." in firefox with the "self.location.."

10-29-2005, 09:26 PM
Heres what I'm using that won't work:


<script type="text/javascript">

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")



<a href="javascript:bookmarksite('document.title', 'self.location.href')">Bookmark this site!</a>

Nothing happens when I click it. It works when you put in a url and title, but not with that^

Anyone ever solve this?

10-30-2005, 02:41 AM
Appears to be a classic case of string vs. variable. When you go:

<a href="javascript:bookmarksite('Home Page', 'http://www.domain.com/index.html')">

You are passing two string literals to the function but, when you go:

<a href="javascript:bookmarksite('document.title', 'self.location.href')">

You are trying to pass two variables. By quoting them, you turn them back into string literals (ones that make no sense to the function, or more precisely, the browsers the function is targeting). The proper method (assuming these variables have the expected values) would be:

<a href="javascript:bookmarksite(document.title, self.location.href)">

without quotes. That way, they will be treated as variables and (if properly defined before this link is clicked) resolved to their assigned values by the function.