DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   "add this site to your bookmarks" in firefox (http://www.daniweb.com/forums/thread21389.html)

MrScruff Apr 3rd, 2005 6:49 pm
"add this site to your bookmarks" in firefox
 
Is it possible to have a link so users can add my site to their bookmarks via a link? I have found out how to do it using IE but it doesn't work with Firefox.

Cheers for anyhelp.

DaveSW Apr 4th, 2005 8:26 am
Re: "add this site to your bookmarks" in firefox
 
This function appears to work in both:
<script type="text/javascript">
function addBookmark(title,url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}
</script>

I'm using that with this link:
<a href="#"
        onmousedown="addBookmark('Williamsons Oldham','http://williamsons-oldham.co.uk/')"><img src="graphics/bookmark.gif" alt="bookmark this page" border=0 /> Bookmark this page</a>

MrScruff Apr 4th, 2005 8:45 am
Re: "add this site to your bookmarks" in firefox
 
Thats a nice little script cheers! I'll try it out soon. :)

Viper May 26th, 2005 9:41 pm
Re: "add this site to your bookmarks" in firefox
 
DaveSW

I love the script. Thanks!

Question: How (if at all), can the "href" command be modified so that - instead of having the title and url "hardcoded" - the command could instead take the "document.title" and the "document.location" (same as I have done for my mailto scripts)...

[document.write(" <a href=\"mailto:?subject=" + escape("Voici un lien à une recette intéressante...") + "& body=" + escape(document.title) + "%0A"+ document.location + "\">") ;]

Thanks...

pablo99 Jul 28th, 2005 12:22 pm
Re: "add this site to your bookmarks" in firefox
 
hey guys. firstly, thanks for your script! ive been searching and google led me here :)

the only problem i have is that the script defaults the bookmark's property so that it opens in the sidebar. would you be able to tell me how to stop this?

thanks!

pablo

DaveSW Jul 30th, 2005 4:46 pm
Re: "add this site to your bookmarks" in firefox
 
Hi Pablo
That doesn't happen for me...
What browser/version are you using?
Dave

pablo99 Aug 1st, 2005 5:08 am
Re: "add this site to your bookmarks" in firefox
 
Hi Dave,

I'm using Firefox 1.0.6 and as I say the bookmark opens in the sidebar. I see there is an option in the bookmark properties to turn it off, but for some reason it defaults to on when the bookmark is created.

Pablo

heepofajeep Jan 21st, 2007 5:43 am
Re: "add this site to your bookmarks" in firefox
 
Cool script-- thank you very much!

My question is, for my application, I would like to be able to have the bookmark refer to a dynamically changed page...

The part of your example that used:
<a href="#"
        onmousedown="addBookmark('Williamsons Oldham','http://williamsons-oldham.co.uk/')"><img src="graphics/bookmark.gif" alt="bookmark this page" border=0 /> Bookmark this page</a>
is the part I would like to change. Ideally, I would like to use ...addBookmark('mysite',<? echo 'http://mysite'; ?>)... Of course, this does not work, so is there a way to make something similar work?

Where I used the php echo, I just used echo to simulate a very simple php command.



I am sure this is more-or-less a fundamental javascript/php interaction question, but unfortunately I am very new to javascript.

Thanks!!!

MattEvans Jan 21st, 2007 12:08 pm
Re: "add this site to your bookmarks" in firefox
 
To 'interact' between javascript and PHP, you have to either use PHP to create javascript code, or use XMLHTTP requests in javascript to access PHP scripts and then handle the output if neccessary.

You cannot write javscript code that directly invokes PHP code. javscript is processed on a client's computer; PHP is processed at the server as a page is requested. Javscript only ever runs after the PHP processor has done its work (and removed all PHP blocks from its output files)

That doesn't mean that you cant create javascript code based on or affected by a PHP process; it just means that the javascript in a PHP file will do what the PHP code tells it to do.

So, by the time javascript runs; this PHP code:

addBookmark('mysite',<? echo 'http://mysite'; ?>)

will always end up as this javscript code:

addBookmark('mysite',http://mysite);

And that code wont work because of quoting.

But this PHP code:

addBookmark('mysite','<? echo 'http://mysite'; ?>');

Generates this code:

addBookmark('mysite','http://mysite');

Which should work.

heepofajeep Jan 22nd, 2007 3:14 am
Re: "add this site to your bookmarks" in firefox
 
Cool, thank you much! That did the trick.

So, just one other item ;)... Do you guys know if there is any way to alter the description of the bookmark? This is more of a firefox thing, but it would still be cool, although not necessary.

Thanks again :cool:

heepofajeep Jan 22nd, 2007 4:16 am
Re: "add this site to your bookmarks" in firefox
 
Quote:

Originally Posted by pablo99 (Post 148010)
Hi Dave,

I'm using Firefox 1.0.6 and as I say the bookmark opens in the sidebar. I see there is an option in the bookmark properties to turn it off, but for some reason it defaults to on when the bookmark is created.

Pablo

X2... I am using Firefox 2.xx

heepofajeep Jan 28th, 2007 9:27 pm
Re: "add this site to your bookmarks" in firefox
 
???

Aegist Apr 13th, 2007 1:15 am
Re: "add this site to your bookmarks" in firefox
 
Hi, two things. First the question about dynamic website name. I use a bit javascript to determine the url (location.href) and then a bit of javascript to determine the pages title (document.title) and assign variables to them. Then use those variables in the link.

I'll give the whole code I use, because my one is slightly different, but really the only difference is the pageurl and pagetitle variables I have set.

<script type="text/javascript">
var pageurl=location.href;
var pagetitle=document.title;

function bookmarksite(title,url){
if (window.sidebar)
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)
    window.external.AddFavorite(url, title);
}
</script>
<p class="newstext"><a class="news" href="javascript:bookmarksite(pagetitle, pageurl)">Bookmark this page</a></p>


Second thing: Firefox. I'm having the sidebar problem too. And i have firefox 2.x. You can save the bookmark fine, but when you try to open it, it opens in the sidebar. Pretty useless for actually visiting a site!

Anyone have a solution to this?

Aegist Apr 13th, 2007 1:22 am
Re: "add this site to your bookmarks" in firefox
 
Just want to subscribe to the thread...

maa_ku May 21st, 2007 2:48 am
Re: "add this site to your bookmarks" in firefox
 
DaveSW, great script! thanks!


All times are GMT -4. The time now is 2:05 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC