bluedogranch
03-02-2007, 05:06 AM
I found this "add favorites" javascript at
http://www.dynamicdrive.com/dynamicindex9/addbook.htm
What I'm wondering is how to make it dynamic, i.e. get the page URL and page title for each page the script is on. I'd like to load the script (with the php print function) on each of my web pages, and have it get the page title and URL from each page so I don't have to code that in for each page.
I figured out how to get the page url into the html link with php, but using php to parse a page title is quite involved.
Anyone know how to do this all in javascript? Would you call variables like:
myURL = window.location.href and myTitle = document.title?
I'm still learning........
javascript:
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);
}
The script is called on the webpage with this:
<a href="javascript:bookmarksite('Dynamic Drive', 'http://www.dynamicdrive.com')">Bookmark this site!</a>
http://www.dynamicdrive.com/dynamicindex9/addbook.htm
What I'm wondering is how to make it dynamic, i.e. get the page URL and page title for each page the script is on. I'd like to load the script (with the php print function) on each of my web pages, and have it get the page title and URL from each page so I don't have to code that in for each page.
I figured out how to get the page url into the html link with php, but using php to parse a page title is quite involved.
Anyone know how to do this all in javascript? Would you call variables like:
myURL = window.location.href and myTitle = document.title?
I'm still learning........
javascript:
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);
}
The script is called on the webpage with this:
<a href="javascript:bookmarksite('Dynamic Drive', 'http://www.dynamicdrive.com')">Bookmark this site!</a>