471,872 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,872 software developers and data experts.

Bookmark on Firefox

Hi, this simple code works well to add a bookmark on IE, but it
doesn't work on Firefox
<a href="javascript:window.external.AddFavorite('http ://
www.mysite.com','My site is cool');">

Can someone suggest me something ?

May 5 '07 #1
5 5230
// Firefox 1.x+, IE4+ and Opera7+

<script type="text/javascript">
<!-- // Begin
function bookmarksite(title,url){
if (window.sidebar) // Firefox
window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // Opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
}
else if(document.all) // IE
window.external.AddFavorite(url, title);
}
// End -->
</script>

<a href="javascript:bookmarksite('Page Title',
'http://www.example.com')">Bookmark this site!</a>
Pipp wrote:
Hi, this simple code works well to add a bookmark on IE, but it
doesn't work on Firefox
<a href="javascript:window.external.AddFavorite('http ://
www.mysite.com','My site is cool');">

Can someone suggest me something ?
May 5 '07 #2
Mad Joe said the following on 5/5/2007 3:36 PM:
// Firefox 1.x+, IE4+ and Opera7+
And broken in many of those and others.
<script type="text/javascript">
<!-- // Begin
Remove the worthless, non-working, useless comments.
function bookmarksite(title,url){
if (window.sidebar) // Firefox
While Firefox may support sidebar, it may not be the only browser that
does. But, at least this branch of the if half tests for what you are using.
window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // Opera
Is there a browser (or even a version of Opera) that doesn't support
window.print? And, why aren't you testing for what you really want to use?
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
}
else if(document.all) // IE
IE is far from the only browser that will enter this branch. AOL, for
one, will pass that test but utterly error out on the call to
window.external, and, there is *no* way to add a favorite in AOL via
scripting.
window.external.AddFavorite(url, title);
}
// End -->
</script>

<a href="javascript:bookmarksite('Page Title',
'http://www.example.com')">Bookmark this site!</a>
What happens if scripting is disabled? And, what happens, in IE, when an
animated gif is on the page? (Test it).

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 5 '07 #3
On Firefox this opens the bookmark on the sidebar, how to open it on
the main window ?

On 5 Mag, 21:36, Mad Joe <M...@Joe.netwrote:
// Firefox 1.x+, IE4+ and Opera7+

<script type="text/javascript">
<!-- // Begin
function bookmarksite(title,url){
if (window.sidebar) // Firefox
window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // Opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();}

else if(document.all) // IE
window.external.AddFavorite(url, title);}

// End -->
</script>

<a href="javascript:bookmarksite('Page Title',
'http://www.example.com')">Bookmark this site!</a>

Pipp wrote:
Hi, this simple code works well to add a bookmark on IE, but it
doesn't work on Firefox
<a href="javascript:window.external.AddFavorite('http ://
www.mysite.com','Mysite is cool');">
Can someone suggest me something ?- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

May 6 '07 #4
Randy Webb wrote:
Remove the worthless, non-working, useless comments.
I'm hiding it because of the stupid W3C validators...
While Firefox may support sidebar, it may not be the only browser that
does. But, at least this branch of the if half tests for what you are
using.
Is there a browser (or even a version of Opera) that doesn't support
window.print? And, why aren't you testing for what you really want to use?
IE is far from the only browser that will enter this branch. AOL, for
one, will pass that test but utterly error out on the call to
window.external, and, there is *no* way to add a favorite in AOL via
scripting.
Ask Frankyboy: http://www.dynamicdrive.com/dynamicindex9/addbook.htm
What happens if scripting is disabled? And, what happens, in IE, when an
animated gif is on the page? (Test it).
What if somebody plugs our visitor's ass on 220V and torture him to
death while another jerk is recording the whole event for publishing on
YouTube? Maybe we should build a script which could prevent that sick
possibility to avoid the mess with the law.
May 7 '07 #5
Mad Joe said the following on 5/6/2007 8:18 PM:
Randy Webb wrote:
>Remove the worthless, non-working, useless comments.

I'm hiding it because of the stupid W3C validators...
The validators are stupid but what does that say of one who uses
something they know to be stupid? Search the archives for my name and
"validator" to get some idea of my thoughts about validators.
>While Firefox may support sidebar, it may not be the only browser that
does. But, at least this branch of the if half tests for what you are
using.
Is there a browser (or even a version of Opera) that doesn't support
window.print? And, why aren't you testing for what you really want to
use?
IE is far from the only browser that will enter this branch. AOL, for
one, will pass that test but utterly error out on the call to
window.external, and, there is *no* way to add a favorite in AOL via
scripting.

Ask Frankyboy: http://www.dynamicdrive.com/dynamicindex9/addbook.htm
Why? "Frankyboy" didn't post that crap code to c.l.j., you did. And that
is what is is - crap code. I simply pointed out a few of the flaws in
code that you posted here.
>What happens if scripting is disabled? And, what happens, in IE, when
an animated gif is on the page? (Test it).

What if somebody plugs our visitor's ass on 220V and torture him to
death while another jerk is recording the whole event for publishing on
YouTube?
The difference is that the scenario I asked about is likely to happen
and very simple to work around. Yours won't ever happen. And, I didn't
make my up out of my visitor's ass with 220V connected to it.

The solution is simple. Don't use a javascript: pseudo-protocol. Don't
want your link breaking if JS is disabled? Simple, have JS create the
element to start with.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 7 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Timothy Wu | last post: by
1 post views Thread by nkparimi | last post: by
2 posts views Thread by Thelma Lubkin | last post: by
6 posts views Thread by Chris | last post: by
1 post views Thread by Cat | last post: by
23 posts views Thread by Stanimir Stamenkov | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.