Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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 11:40 PM.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,855
    Thanks
    22
    Thanked 157 Times in 148 Posts
    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 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • Users who have thanked chump2877 for this post:

    grid_ (08-21-2011)

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,855
    Thanks
    22
    Thanked 157 Times in 148 Posts
    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 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • Users who have thanked chump2877 for this post:

    grid_ (08-21-2011)

  • #5
    New Coder
    Join Date
    Jul 2011
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Chump,
    Thank you again

    Greets grid


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •