Home  >  Article  >  Web Front-end  >  Universal add-to-favorites code supports IE Firefox and other browsers_javascript skills

Universal add-to-favorites code supports IE Firefox and other browsers_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:11:541155browse

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> function addfavorite() { switch(getOs()) { case 1:window.external.addFavorite('http://www.jb51.net','脚本之家 ');break; case 2:window.sidebar.addPanel('脚本之家', 'http://www.jb51.net/', "");break; case 0:alert("您的浏览器也太牛了,我都不知道如何显示了。 唉。");break; } } function getOs() { if(navigator.userAgent.indexOf("MSIE")>0)return 1; if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2; if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3; if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4; if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5; return 0; } </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn