...

View Full Version : Select a value from a combobox to bookmark it with a button



grid_
07-23-2011, 11:17 PM
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

chump2877
07-24-2011, 03:39 AM
Here is one way to do it:


<?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=opera&rls=en&q=javascript+to+bookmark+page&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest#sclient=psy&hl=en&safe=off&client=opera&hs=oKT&rls=en&channel=suggest&source=hp&q=javascript+bookmark+page&aq=0&aqi=g3g-v2&aql=&oq=&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=c99a1973f6c67dac&biw=1346&bih=870

grid_
07-24-2011, 01:29 PM
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

chump2877
07-24-2011, 01:38 PM
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:


<?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>

grid_
07-25-2011, 12:15 AM
Chump,
Thank you again :)

Greets grid



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum