Forum Moderators: open
I'm trying to have the user click a link. When that link is clicked, I want to call a javascript function and pass variables.
Here's the header code (I've removed unrelated bits):
<script type="text/javascript">
function saveme(title, url)
{
if (window.sidebar)
{
window.sidebar.addPanel(title, url, "");
}
else
{
return true;
}
}
</script>
As you can see, this code just adds the given variables as a Bookmark in Firefox. Now, here's the body code:
<script type="text/javascript">
if (window.sidebar)
{
var doctitle = document.title;
var doclocation = document.location;
var args = "<a href='javascript:saveme(doctitle, doclocation)'>clickme</a>";
document.write(args);
}
</script>
And it fails with the console message that "saveme is not defined". No matter what I do, I can't fix this. From what I can tell, the function isn't even being called. I *can* get the function to call if I simplify the link above. Specifically, if I take out the href stuff, and just do something like this:
if (window.sidebar)
{
var doctitle = document.title;
var doclocation = document.location;
document.write(saveme(doctitle, doclocation));
}
This leads me to believe this is some goofy syntax formatting requirement on Firefox's end.
Can anyone tell me why my first two code snippets don't work? And how I can get them to work?
Thanks!
Andy
<script type="text/javascript">
if (window.external)
{
document.write(' or <a href="javascript:saveme(document.title, document.location)");">add page to Favorites</a>');
}
else if (window.sidebar)
{
document.write(' or <a href="javascript:saveme(document.title, document.location)");">add Bookmark</a>');
}
else if (window.opera && window.print)
{
document.write(' or <a href="javascript:saveme(document.title, document.location)");">add Bookmark</a>');
}
</script>
...And it looks like this, too, works in an "empty" html, but not in my own document.
Does this answer your question?
<BASE TARGET="_top">
...And it was overriding the Firefox HREF call. So I put in a target=_self call, like this:
document.write(' or <a target=_self href="javascript:saveme(document.title, document.location)");">add Bookmark</a>');
And, as they say, "voila".
Thanks for getting me there!
Andy