Connecting Tech Pros Worldwide Forums | Help | Site Map

Bookmark on Firefox

Pipp
Guest
 
Posts: n/a
#1: May 5 '07
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 ?


Mad Joe
Guest
 
Posts: n/a
#2: May 5 '07

re: Bookmark on Firefox


// 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:
Quote:
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 ?
>
Randy Webb
Guest
 
Posts: n/a
#3: May 5 '07

re: Bookmark on Firefox


Mad Joe said the following on 5/5/2007 3:36 PM:
Quote:
// Firefox 1.x+, IE4+ and Opera7+
And broken in many of those and others.
Quote:
<script type="text/javascript">
<!-- // Begin
Remove the worthless, non-working, useless comments.
Quote:
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.
Quote:
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?
Quote:
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.
Quote:
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/
Pipp
Guest
 
Posts: n/a
#4: May 6 '07

re: Bookmark on Firefox


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:
Quote:
// 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:
Quote:
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');">
>
Quote:
Can someone suggest me something ?- Nascondi testo tra virgolette -
>
- Mostra testo tra virgolette -

Mad Joe
Guest
 
Posts: n/a
#5: May 7 '07

re: Bookmark on Firefox


Randy Webb wrote:
Quote:
Remove the worthless, non-working, useless comments.
I'm hiding it because of the stupid W3C validators...
Quote:
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
Quote:
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.
Randy Webb
Guest
 
Posts: n/a
#6: May 7 '07

re: Bookmark on Firefox


Mad Joe said the following on 5/6/2007 8:18 PM:
Quote:
Randy Webb wrote:
Quote:
>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.
Quote:
Quote:
>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.
Quote:
Quote:
>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/
Closed Thread