Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript Add to Bookmarks link

Posted on 2011-02-15
2
Medium Priority
?
789 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logiā€¦
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

886 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