Solved

Javascript Add to Bookmarks link

Posted on 2011-02-15
2
784 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 200 total points
ID: 34899597
0
 
LVL 55

Accepted Solution

by:
Huseyin KAHRAMAN earned 300 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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?
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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