Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-23-2011, 10:17 PM   PM User | #1
grid_
New to the CF scene

 
Join Date: Jul 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
grid_ is an unknown quantity at this point
Select a value from a combobox to bookmark it with a button

Hello folks,
I want to have a combobox with bookmark options. After you select a value from this combobox you can bookmark it with a push button. This should popup a bookmark dialog from the browser bookmark dialog. Can anybody help me?

Lets say we have 3 options in the value's. Google, Yahoo, Bing
When you select Google and you push Place bookmark you should get a browser bookmark dialog with a title "Google search site". The url would be just http://www.google.com/

I also want Yahoo with the url http://www.yahoo.com/ and the bookmark title Search at Yahoo! and Bing with the url http://www.bing.com and the title Search at Bing

I'm looking already for a while for this. Can anybody help me?

Thanks in advance!

grid

Last edited by grid_; 07-23-2011 at 10:40 PM..
grid_ is offline   Reply With Quote
Old 07-24-2011, 02:39 AM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Here is one way to do it:

Code:
<?xml version="1.1" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>TITLE</title>
</head>
<body>

<select id="urls">
	<option value="http://google.com">Search at Google</option>
	<option value="http://yahoo.com">Search at Yahoo</option>
	<option value="http://bing.com">Search at Bing</option>
</select><br />
<input type="button" value="Add Bookmark" id="bookmarkButton" />

<script type="text/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);
		}
	}

	document.getElementById('bookmarkButton').onclick = function()
	{
		var urlsMenu = document.getElementById('urls');
		bookmarksite(urlsMenu.options[urlsMenu.selectedIndex].text, urlsMenu.options[urlsMenu.selectedIndex].value);
	};
</script>

</body>
</html>
The bookmarksite() function is copied directly from here: http://www.dynamicdrive.com/dynamicindex9/addbook.htm

If you want a different way to bookmark sites, there are plenty of JS bookmark functions to be found here: http://www.google.com/search?client=...w=1346&bih=870
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Users who have thanked chump2877 for this post:
grid_ (08-21-2011)
Old 07-24-2011, 12:29 PM   PM User | #3
grid_
New to the CF scene

 
Join Date: Jul 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
grid_ is an unknown quantity at this point
Hello Chump, thanks! There is only one request I still need. I wanted to have the bookmark title different from the values you select from. Lets say there are only 3 choices Google, Yahoo!, Bing, then your bookmark title would be like Search at Googe etc


Thanks in advance!

Greets grid
grid_ is offline   Reply With Quote
Old 07-24-2011, 12:38 PM   PM User | #4
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
Originally Posted by grid_ View Post
I wanted to have the bookmark title different from the values you select from. Lets say there are only 3 choices Google, Yahoo!, Bing, then your bookmark title would be like Search at Googe etc
See changes in red:

Code:
<?xml version="1.1" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>TITLE</title>
</head>
<body>

<select id="urls">
	<option value="http://google.com">Google</option>
	<option value="http://yahoo.com">Yahoo</option>
	<option value="http://bing.com">Bing</option>
</select><br />
<input type="button" value="Add Bookmark" id="bookmarkButton" />

<script type="text/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);
		}
	}

	document.getElementById('bookmarkButton').onclick = function()
	{
		var urlsMenu = document.getElementById('urls');
		bookmarksite("Search at "+urlsMenu.options[urlsMenu.selectedIndex].text, urlsMenu.options[urlsMenu.selectedIndex].value);
	};
</script>

</body>
</html>
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Users who have thanked chump2877 for this post:
grid_ (08-21-2011)
Old 07-24-2011, 11:15 PM   PM User | #5
grid_
New to the CF scene

 
Join Date: Jul 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
grid_ is an unknown quantity at this point
Chump,
Thank you again

Greets grid
grid_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43 AM.


Advertisement
Log in to turn off these ads.