The add to favorites function is a common feature. I have studied it today and wrote a simple example to implement the add to favorites function:
The html code is as follows:
<A href = "#" id = "favorites"> Add this page to favorites </a>
The jQuery code is as follows:
$ (Document). ready (function (){
$ ("# Favorites"). click (function (){
Var ctrl = (navigator. userAgent. toLowerCase (). indexOf ('mac ')! =-1? 'COMMAND/cmd': 'ctrl ';
If (document. all ){
Window. external. addFavorite ('HTTP: // blog.csdn.net/yilanyoumeng3', 'frontend autumn ');
}
Else if (window. sidebar ){
Window. sidebar. addPanel ('front-end Qiuqiu ', 'HTTP: // blog.csdn.net/yilanyoumeng3 ',"");
}
Else {alert ('you can use the shortcut key '+ ctrl +' + D to add to favorites ');}
})
})
Although some browser-compatible functions are implemented, due to limited knowledge, there may be many shortcomings.
Author: yilanyoumeng3