Improve company productivity with a Business Account.Sign Up

x
?
Solved

Javascript Add to Bookmarks link

Posted on 2011-02-15
2
Medium Priority
?
794 Views
Last Modified: 2012-05-11
Can someone please let me know how I can get the following script to work in chrome?

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

<a href="#" onclick="Javascript:bookmark('http://www.mysite.com/', 'Some Title')"><img alt="Add to favorites" src="http://www.myslte.com/images/favorites_bookmark.png" height="20" width="20"></a>

it works fine in firefox and IE.

Thanks

Mike
0
Comment
Question by:hungoveragain
2 Comments
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 800 total points
ID: 34899597
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 1200 total points
ID: 34899768
chrome is goint to this part

} else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  }

and Chrome does not allow adding bookmarks by JS...
use this code:
<script>
function bookmark(url,title){
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if ((navigator.appName == "Netscape") && (!is_chrome)) {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape / Chrome) or CTRL-T (Opera) to bookmark");
  }
}
</script>

<a href="#" onclick="javascript:bookmark('http://www.mysite.com/', 'Some Title')"><img alt="Add to favorites" src="http://www.myslte.com/images/favorites_bookmark.png" height="20" width="20"></a>

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question