PDA

View Full Version : Help with 'Bookmark this page' script.



john2010
04-04-2011, 02:17 PM
1) Script Title: Bookmark Site script

2) http://dynamicdrive.com/dynamicindex9/addbook.htm

3) Hello, could I get some help with customizing this script so that it bookmarks only the page that its transferred to ? For example, I run a weather site and would like my visitors to have the option to 'bookmark this forecast' after entering their zipcode. (thus, the url's are different all the time)

So far all I could see is that we must specify the url in this script. Anyway to be able to specifically bookmark the page that they land on ?

any help is much appreciated.

ddadmin
04-04-2011, 10:07 PM
Well, the function of the script can be passed in a different set of bookmark title and URL to bookmark that page:


bookmarksite('Dynamic Drive', 'http://cnn.com')

Instead of the above, you can enter a set of variables as the parameters instead:


<a href="javascript:bookmarksite(booktitle, bookurl)">Bookmark this site!</a>

in which the actual bookmark page's title and URL is defined inside these two variables:


<script>
var booktitle="Dynamic Drive"
var bookurl="http://www.dynamicdrive.com"
</script>

Pending some action of your choice, you'd modify the values of these two JavaScript variables, and the bookmark will change accordingly when the bookmark script is called. If you need more help let us know.

john2010
06-12-2011, 12:02 AM
arghh, sorry I forgot about this thread..

I finally got around to messing around with this & got it to work with var's ddadmin mentioned.

works fine in IE.

but it looks like the new version of FireFox doesn't mix well with this script.

When you click on "Book Dynamic Drive" from your own page (with FireFox) -

http://dynamicdrive.com/dynamicindex9/addbook.htm

after bookmarking... click on the bookmark... it opens the site within the small bookmark column...instead of the main window to its right like it's suppose to.

:(

jscheuer1
06-12-2011, 06:51 AM
That's always been a limitation of Firefox. The only javascript bookmarks it accepts are those kind, AKA sidebar. They can always be converted by the user to normal by unchecking the open in sidebar checkbox.

john2010
06-12-2011, 03:39 PM
They can always be converted by the user to normal by unchecking the open in sidebar checkbox.

This is an option in FireFox ? (I can't seem to locate it)

last question after the above :

I've got the var bookmark url looking somewhat similar to this -

var bookurl="%%fulljurl%%%%place%%.html"

the place variable specifically outputs the current town. And it works fine if the town is 1 word. But occasionally towns have more than 1 word. (example, new york city , mount pocono , etc )

my current program only recognizes the + symbol as the space identifier. but when adding to bookmark, it outputs spaces as %20 , which in turn makes the URL a dead link.

think there's an ez fix for this ? Any help is greatly appreciated.

jscheuer1
06-12-2011, 05:24 PM
In Firefox make a bookmark using this script. Then find it in the Bookmarks menu. Right click on it, choose properties. Uncheck the checkbox labeled:

Load this bookmark in the sidebar

As to your other question, %20 is usually a valid stand in for a space character in a URL. I'm uncertain of your overall setup or of the amount of control we can exert over the script.

The two obvious choices would be:


Get it to stop using %20


Use a different delimiter in the place name something other than space, ie: new_york_city


If it's not too much trouble to implement, #2 would be more certain. However, %20 is simply the escaped version of space for URL's. We could try (addition highlighted):


<script type="text/javascript">

/***********************************************
* Bookmark site script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
url = unescape(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);
}
</script>